嵌入控件的控件,最好用wndproc回调函数处理消息。否则应在父控件窗口中转发命令消息

示例1 

  1. import win.ui;
  2. /*DSG{{*/
  3. var winform = ..win.form( bottom=399;parent=...;text="AAuto Form";right=599 )
  4. winform.add(
  5. listview={ bgcolor=16777215;bottom=291;right=520;left=21;top=46;z=1;gridLines=1;edge=1;cls="listview" };
  6. edit={ text="edit";bottom=363;right=431;left=82;top=337;z=2;edge=1;cls="edit" }
  7. )
  8. /*}}*/

  9. winform.listview.insertColumn("dfdfd",150)
  10. winform.listview.insertColumn("dfdfd",150)
  11. winform.listview.insertColumn("dfdfd",-1)
  12. winform.listview.addItem({"sdfsdf";'sdfd645';'fkdl'})
 
  // 插入控件
  1. winform.listview.addCtrl(
  2.     btn = {
  3.         cls="button";left=0;top=0;right=50;bottom=50;autoResize=false ;edge=1;
  4.         oncommand=function(id,event){
  5.             winform.msgboxTest(winform.edit.text)
  6.         }
  7.     }
  8. )
//winform.cmdTranslate 转发命令消息,在父控件wndproc消息回调中调用,用于启用子控件的oncommand事件.
  1. winform.listview.wndproc = function(hwnd,message,wParam,lParam){
  2.     winform.cmdTranslate(hwnd,message,wParam,lParam);
  3. }
// 设置内嵌控件的位置
  1. var rc = winform.listview.getItemRect(1,3,,2)
  2. winform.listview.btn.setRect(rc)

  3. winform.show()
  4. win.loopMessage();
示例 2 

  1. import win.ui;
  2. /*DSG{{*/
  3. var winform = ..win.form( bottom=356;parent=...;text="AAuto Form";right=351 )
  4. winform.add(
  5. listview={ bgcolor=16777215;bottom=296;right=309;left=37;top=41;z=1;edge=1;cls="listview" }
  6. )
  7. /*}}*/

  8. winform.listview.addCtrl(
  9.     btn1 ={ cls="button";left=0;top=0;right=50;bottom=50;autoResize=false ;hide=1;edge=1;hide=0;text="btn1";id=100;z=1 };
  10.     btn2 ={ cls="button";left=0;top=52;right=50;bottom=102;autoResize=false ;hide=1;edge=1;hide=0;text="btn2";id=101;z=2 };
  11.     btn3 ={ cls="button";left=0;top=104;right=50;bottom=154;autoResize=false ;hide=1;edge=1;hide=0;text="btn3";id=102;z=3 };
  12.     btn4 ={ cls="button";left=0;top=156;right=50;bottom=206;autoResize=false ;hide=1;edge=1;hide=0;text="btn4";id=103;z=4 };
  13. )

  14. winform.listview.wndproc = function(hwnd, message, wParam, lParam) {
  15.     winform.cmdTranslate(hwnd, message, wParam, lParam);
  16. }

  17. winform.listview.btn1.oncommand = function () {
  18.     winform.msgbox("我是 btn1");
  19. }

  20. winform.listview.btn2.oncommand = function () {
  21.     winform.msgbox("我是 btn2");
  22. }

  23. winform.show()
  24. win.loopMessage();

02-02 20:16