plus模拟右键菜单研究
By
admin
at 2018-02-04 • 1人收藏 • 1211人看过
import win.ui; /*DSG{{*/ mainForm = win.form(text="plus模拟菜单";right=663;bottom=352;bgcolor=8421376) mainForm.add() /*}}*/ var menufuc = function(menumode){ menumode.skin( color = { hover = 0xFF3a9ff7; } ) /* menumode.oncommand = function(id,event){ mainForm.msgbox(menumode) } */ } //win.ui.menu var ddd = 1; var tabmenu = {}; var menutitle = {"第一个菜单";"第二个菜单";"第三个菜单";{"包含子菜单";{"子菜单1";"子菜单2"}}} mainForm.wndproc = function(hwnd,message,wParam,lParam){ select( message ) { case 0x205/*_WM_RBUTTONUP*/{ //鼠标右键弹起,下面获取坐标 var x,y = win.getMessagePos(lParam); var lieadd = 0; if(#tabmenu){ ddd = 1; lieadd = 0; for(k,v in tabmenu){ //if(type(v) != "table"){ mainForm[v].close() table.remove(tabmenu,k); //} } } for(k,v in menutitle){ if(type(v) != "table"){ owner.add( ["menuplus"++ddd] ={cls="plus";text=v;left=x;top=y+25*lieadd;right=x+128;bottom=y+25*(lieadd+1);align="left";background="\res\cdbg2.fw.png";notify=1;paddingLeft=32;repeat="center";x=0.5;dl=1;dt=1}; ) menufuc(owner["menuplus"++ddd]) table.push(tabmenu,"menuplus"++ddd); ddd++; lieadd++; }else { owner.add( ["menuplus"++ddd] ={cls="plus";text=v[1];left=x;top=y+25*lieadd;right=x+128;bottom=y+25*(lieadd+1);align="left";background="\res\cdbg.fw.png";notify=1;paddingLeft=32;repeat="center";x=0.5;dl=1;dt=1}; ) //menufuc(owner["menuplus"++ddd]) owner["menuplus"++ddd].onMouseHover = function(wParam,lParam){ for(k2,v2 in v[2]){ mainForm.add( ["menuplus"++ddd] ={cls="plus";text=v2;left=x+128;top=y+25*(lieadd-1);right=x+128*2;bottom=y+25*(lieadd);align="left";background="\res\cdbg2.fw.png";notify=1;paddingLeft=32;repeat="center";x=0.5;dl=1;dt=1}; ) menufuc(mainForm["menuplus"++ddd]) table.push(tabmenu,"menuplus"++ddd); ddd++; lieadd++; } } table.push(tabmenu,"menuplus"++ddd); ddd++; lieadd++; } //menufuc(owner["menuplus"++ddd]); /* table.push(tabmenu,"menuplus"++ddd); ddd++; lieadd++; */ } } else{ } } //无返回值则继续调用默认回调函数 } mainForm.enableDpiScaling(); mainForm.show(); return win.loopMessage();
越界/调整大小/...还有很多问题..
1 个回复 | 最后更新于 2018-02-04
登录后方可回帖
菜单是支持自绘的,自绘的方法跟范例中的listbox一样。
import win.ui;
import win.ui.menu;
/*DSG{{*/var winform = win.form(text="菜单用法演示";right=349;bottom=249) /*}}*/
win.ui.menu.onMeasureItem = function(measureItem){ }
win.ui.menu.onDrawItem = function(drawItem){ }
var menuFile = win.ui.popmenu(winform);
menuFile.ownerDraw = true;
winform.show()
win.loopMessage();
需要定义这几个函数,关于高级界面不完美这个问题,完美这个东西是没有边界的,而且你首先是要从基础学起,不可能一下子就能做出非常完美的界面了。