最近做程序,需要在一个listview里面嵌入一个按钮,但是请嵌入的按钮无法做出响应。到论坛求助后才得到前辈指点:”这种嵌入控件的控件,最好用wndproc回调函数处理消息。
否则应在父控件窗口中转发命令消息。“
第一种方法:用wndproc回调函数处理消息
import win.ui;
/*DSG{{*/
var winform = ..win.form( bottom=356;parent=…;text=“AAuto Form”;right=351 )
winform.add(
listview={ bgcolor=16777215;bottom=296;right=309;left=37;top=41;z=1;edge=1;cls=“listview” }
)
/*}}*/
//winform.richedit.text = “”
winform.listview.addCtrl(
[“btn1”] ={ cls=“button”;left=0;top=0;right=50;bottom=50;autoResize=false ;hide=1;edge=1;hide=0;text=“btn1”;id=100; };
)
winform.listview.addCtrl(
[“btn2”] ={ cls=“button”;left=0;top=52;right=50;bottom=102;autoResize=false ;hide=1;edge=1;hide=0;text=“btn2”;id=101; };
)
winform.listview.addCtrl(
[“btn3”] ={ cls=“button”;left=0;top=104;right=50;bottom=154;autoResize=false ;hide=1;edge=1;hide=0;text=“btn3”;id=102; };
)
winform.listview.addCtrl(
[“btn4”] ={ cls=“button”;left=0;top=156;right=50;bottom=206;autoResize=false ;hide=1;edge=1;hide=0;text=“btn4”;id=103; };
)
winform.listview.wndproc = function(hwnd,message,wParam,lParam){
select(message) {
case 0x111/*_WM_COMMAND*/ {
select(wParam) {
case 100 {
winform.msgbox(“我是按钮1 btn1”)
}
case 101 {
winform.msgbox(“我是按钮2 btn2”)
}
case 102 {
winform.msgbox(“我是按钮3 btn3”)
}
case 103 {
winform.msgbox(“我是按钮4 btn4”)
}
}
}
}
//无返回值则继续调用默认回调函数
}
winform.show()
win.loopMessage();
第二种方法:父控件转发消息
import win.ui;
/*DSG{{*/
var winform = ..win.form( bottom=399;parent=…;text=“AAuto Form”;right=599 )
winform.add(
listview={ bgcolor=16777215;bottom=291;right=520;left=21;top=46;z=1;gridLines=1;edge=1;cls=“listview” };
edit={ bottom=363;text=“edit”;left=82;top=337;z=2;right=431;edge=1;cls=“edit” }
)
/*}}*/
winform.listview.insertColumn(“dfdfd”,150)
winform.listview.insertColumn(“dfdfd”,150)
winform.listview.insertColumn(“dfdfd”,-1)
winform.listview.addItem({“sdfsdf”;‘sdfd645’})
io.open()
winform.listview.addCtrl(
edit = {
cls=“button”;left=0;top=0;right=50;bottom=50;autoResize=false ;edge=1;
oncommand=function(id,event){
io.print(“1111”)
}
}
)
winform.listview.wndproc = function(hwnd,message,wParam,lParam){
winform.cmdTranslate(hwnd,message,wParam,lParam);
//此处是关键,实现消息转发,子控件才能接收响应
}
var rc = winform.listview.getItemRect(1,2,,2)
winform.listview.edit.setRect(rc)
winform.show()
win.loopMessage();
最新评论