WINAPI
CheckMenuItem(
_In_ HMENU hMenu,//菜单句柄
_In_ UINT uIDCheckItem,//菜单ID
_In_ UINT uCheck)//复选标记MF_CHECKED(添加复选标记)和MF_UNCHECKED(取消复选标记)
实例:
LRESULT MyWnd::OnCommand(DWORD dwID, DWORD dwEnter, HWND hCtrlWnd)
{
HMENU hMenu = GetMenu(m_hWnd)//获得窗口菜单句柄
HMENU hItem = GetSubMenu(hMenu, 1)//获得第二个子菜单项的句柄
switch (dwID)
{
case ID_TOOBAR_MENU:
{
//判断是否有复选标记,如果有就取消复选标记,没有就添加复选标记
if (CheckMenuItem(hItem, ID_TOOBAR_MENU, MF_CHECKED)&MF_CHECKED)
CheckMenuItem(hItem, ID_TOOBAR_MENU, MF_UNCHECKED)
break
}
case ID_STAT_MENU:
{
if (CheckMenuItem(hItem, ID_STAT_MENU, MF_CHECKED)&MF_CHECKED)
CheckMenuItem(hItem, ID_STAT_MENU, MF_UNCHECKED)
break
}
case ID_MENU_MENU:
{
if (CheckMenuItem(hItem, ID_MENU_MENU, MF_CHECKED)&MF_CHECKED)
CheckMenuItem(hItem, ID_MENU_MENU, MF_UNCHECKED)
break
}
}
return 0
一个窗口中是不能创建多个菜单的SetMenu只能在没有菜单的窗口中把资源文件中定义的菜单添加进去
CreateWindow创建WD_CHILD风格的窗口是不能定义菜单项的
所以,木有这个api。
下面来介绍一下如何在win32 中实现点击右键d出菜单,步骤如下:1:先在头文件中中先定义三个IDM资源, #define IDM_AAA200 #define IDM_BBB201 #define IDM_CCC 2022.定义一个全局变量 HMENU hMenu3.在InitInstance中添加代码: hMenu=CreatePopupMenu()AppendMenu(hMenu,MF_STRING,IDM_AAA,_T("&AAA"))AppendMenu(hMenu,MF_SEPARATOR,0,NULL)AppendMenu(hMenu,MF_STRING,IDM_BBB,_T("&BBB"))AppendMenu(hMenu,MF_STRING,IDM_CCC,_T("&CCC"))4在WM_RBUTTONDOWN中添加响应代码POINT point;point.x=LOWORD(lParam)point.y=HIWORD(lParam)ClientToScreen(hWnd,&point)TrackPopupMenu(hMenu,TMP_RIGHTALIGN,point.x,point.y,0,hWnd,NULL)当单击某个菜单项时,还可以设置该项位选中状态。CheckMenuItem(hMenu,IDM_AAA,MF_CHECKED)欢迎分享,转载请注明来源:内存溢出
评论列表(0条)