有的时候,菜单中会有单选和多选,如图:
其实主要是通过两个函数CheckMenuItem和CheckMenuRadioItem来实现,
创建好菜单后,在回调函数的WM_COMMAND中进行处理就可以了.
以下是创建菜单和WM_COMMAND消息响应的部分代码(完整工程下载)
;;==================================================== ;;创建菜单的子程序 ;;==================================================== _CreateMenu proc LOCAL @hMenu LOCAL @hPopMenu1 LOCAL @hPopMenu2 LOCAL @hPopMenu3 invoke CreateMenu mov @hMenu,eax ;;-------------------------------------------------- invoke CreatePopupMenu mov @hPopMenu1,eax invoke AppendMenu,@hPopMenu1,MF_STRING,IDM_OPEN,CTEXT("Open") invoke AppendMenu,@hPopMenu1,MF_STRING,IDM_EXIT,CTEXT("Exit") ;;-------------------------------------------------- invoke CreatePopupMenu mov @hPopMenu2,eax invoke AppendMenu,@hPopMenu2,MF_STRING,IDM_BIG,CTEXT("Big") invoke AppendMenu,@hPopMenu2,MF_STRING,IDM_MIDDLE,CTEXT("Middle") invoke AppendMenu,@hPopMenu2,MF_STRING,IDM_SMALL,CTEXT("Small") ;;-------------------------------------------------- invoke CreatePopupMenu mov @hPopMenu3,eax invoke AppendMenu,@hPopMenu3,MF_STRING,IDM_TOOLBAR,CTEXT("ToolBar") invoke AppendMenu,@hPopMenu3,MF_STRING,IDM_STATUSBAR,CTEXT("StatusBar") invoke AppendMenu,@hPopMenu3,MF_STRING,IDM_SIDEBAR,CTEXT("SideBar") ;;-------------------------------------------------- invoke AppendMenu,@hMenu,MF_POPUP,@hPopMenu1,CTEXT("File") invoke AppendMenu,@hMenu,MF_POPUP,@hPopMenu2,CTEXT("Single Check") invoke AppendMenu,@hMenu,MF_POPUP,@hPopMenu3,CTEXT("Multi Check") push @hMenu pop eax ret _CreateMenu endp ;;==================================================== ;;==================================================== ;;消息响应中的WM_COMMAND部分 ;;==================================================== .elseif eax==WM_COMMAND mov eax,wParam movzx eax,ax ;;------------[single check]------------------------------------- .if eax>=IDM_BIG && eax<=IDM_SMALL .if eax==IDM_BIG invoke CheckMenuRadioItem,hMenu,IDM_BIG,IDM_SMALL,ax,MF_BYCOMMAND invoke MessageBox,NULL,CTEXT("Big Checked"),CTEXT("INFO"),MB_OK .elseif eax==IDM_MIDDLE invoke CheckMenuRadioItem,hMenu,IDM_BIG,IDM_SMALL,ax,MF_BYCOMMAND invoke MessageBox,NULL,CTEXT("Middle Checked"),CTEXT("INFO"),MB_OK .elseif eax==IDM_SMALL invoke CheckMenuRadioItem,hMenu,IDM_BIG,IDM_SMALL,ax,MF_BYCOMMAND invoke MessageBox,NULL,CTEXT("Small Checked"),CTEXT("INFO"),MB_OK .endif ;;-----------[multi check]--------------------------------------- .elseif eax>=IDM_TOOLBAR && eax<=IDM_SIDEBAR mov ebx,eax .if eax==IDM_TOOLBAR invoke GetMenuState,hMenu,ebx,MF_BYCOMMAND .if eax==MF_CHECKED invoke MessageBox,NULL,CTEXT("ToolBar Unchecked"),CTEXT("INFO"),MB_OK mov eax,MF_UNCHECKED .else invoke MessageBox,NULL,CTEXT("ToolBar Checked"),CTEXT("INFO"),MB_OK mov eax,MF_CHECKED .endif invoke CheckMenuItem,hMenu,ebx,eax .elseif eax==IDM_STATUSBAR invoke GetMenuState,hMenu,ebx,MF_BYCOMMAND .if eax==MF_CHECKED invoke MessageBox,NULL,CTEXT("StatusBar Unchecked"),CTEXT("INFO"),MB_OK mov eax,MF_UNCHECKED .else invoke MessageBox,NULL,CTEXT("StatusBar Checked"),CTEXT("INFO"),MB_OK mov eax,MF_CHECKED .endif invoke CheckMenuItem,hMenu,ebx,eax .elseif eax==IDM_SIDEBAR invoke GetMenuState,hMenu,ebx,MF_BYCOMMAND .if eax==MF_CHECKED invoke MessageBox,NULL,CTEXT("SideBar Unchecked"),CTEXT("INFO"),MB_OK mov eax,MF_UNCHECKED .else invoke MessageBox,NULL,CTEXT("SideBar Checked"),CTEXT("INFO"),MB_OK mov eax,MF_CHECKED .endif invoke CheckMenuItem,hMenu,ebx,eax .endif .endif