备注:(1)打开工程目录下的"Exe\GUISimulationDebug.exe"即可看到效果。(2)看完教程000~005就基本会用emWin做项目,其他章节可以需要时再参考。
因为emWin的GUIBuilder比较弱智,我们只能用变通的方法创建MENU控件,然后生成C文件之后再做配置修改
(1)用GUIBuilder创建4个MENU控件,第1个横放,另外3个画成竖放形状(但GUIBuilder不能改成竖放,只能生成C文件之后再修改):
(2)保存为C文件FramewinDLG.c,然后添加到脱机模拟仿真平台CodeBlocks的emwin工程,并且编译运行,修改C文件前的显示效果如下:
(3)修改MENU①②③为竖向:
staticconst GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 320, 240,0, 0x64, 0 },
{MENU_CreateIndirect, "Menu", ID_MENU_0, 10, 10, 280, 20, 0, 0x0, 0 },
{MENU_CreateIndirect, "Menu", ID_MENU_1, 10, 45, 60, 150,MENU_CF_VERTICAL, 0x0, 0 },
{MENU_CreateIndirect, "Menu", ID_MENU_2, 85, 45, 60, 150,MENU_CF_VERTICAL, 0x0, 0 },
{MENU_CreateIndirect, "Menu", ID_MENU_3, 160, 45, 60, 150,MENU_CF_VERTICAL, 0x0, 0 },
};(4)修改所有Item的ID:
#defineID_MENU_00 (GUI_ID_USER + 10)
#defineID_MENU_01 (GUI_ID_USER + 11)
#defineID_MENU_02 (GUI_ID_USER + 12)
#defineID_MENU_10 (GUI_ID_USER + 13)
#defineID_MENU_11 (GUI_ID_USER + 14)
#defineID_MENU_12 (GUI_ID_USER + 15)
#defineID_MENU_20 (GUI_ID_USER + 16)
#defineID_MENU_21 (GUI_ID_USER + 17)
#defineID_MENU_22 (GUI_ID_USER + 18)
#defineID_MENU_23 (GUI_ID_USER + 19)
#defineID_MENU_24 (GUI_ID_USER + 20)
#define ID_MENU_30 (GUI_ID_USER + 21)(5)在WM_INIT_DIALOG初始化消息中加入初始化代码,将MENU①加入到主MENU中:
hItem= WM_GetDialogItem(pMsg->hWin, ID_MENU_0);
ItemData.Flags = 0;
ItemData.hSubmenu= WM_GetDialogItem(pMsg->hWin, ID_MENU_1);
ItemData.Id = ID_MENU_00;
ItemData.pText = "File";
MENU_SetItem(hItem, ID_MENU_00, &ItemData);(6)用同样的代码将MENU②③加入到主MENU中:
hItem= WM_GetDialogItem(pMsg->hWin, ID_MENU_0);
ItemData.Flags = 0;
ItemData.hSubmenu= WM_GetDialogItem(pMsg->hWin, ID_MENU_2);
ItemData.Id = ID_MENU_01;
ItemData.pText = "New";
MENU_SetItem(hItem,ID_MENU_01, &ItemData);
hItem= WM_GetDialogItem(pMsg->hWin, ID_MENU_0);
ItemData.Flags = 0;
ItemData.hSubmenu= WM_GetDialogItem(pMsg->hWin, ID_MENU_3);
ItemData.Id = ID_MENU_02;
ItemData.pText = "About";
MENU_SetItem(hItem,ID_MENU_02, &ItemData);
(7)用FRAMEWIN_AddMenu()函数将MENU附贴到Framewin顶部:
FRAMEWIN_AddMenu(pMsg->hWin,WM_GetDialogItem(pMsg->hWin, ID_MENU_0));
(8)修改MENU①②③的高度,否则将出现以下显示现象:
(9)在WM_NOTIFY_PARENT消息中(操作屏幕时程序跑到这里)加入代码:
case WM_MENU://MENU控件触发消息(操作MENU后到这里)
p_data = (MENU_MSG_DATA*)pMsg->Data.p;
switch (p_data->MsgType) {
case MENU_ON_ITEMPRESSED:
break;
case MENU_ON_ITEMACTIVATE:
break;
case MENU_ON_ITEMSELECT:
MENU_GetItem(pMsg->hWinSrc, p_data->ItemId,&data);
if (data.Flags & MENU_IF_DISABLED) break;
EDIT_SetValue(WM_GetDialogItem(pMsg->hWin, ID_EDIT_0),data.Id);
break;
}
WM_DefaultProc(pMsg);
break;