c – 为什么我没有收到WM_MENUCHAR消息?
作者:互联网
我实现了一个IContextMenu3接口,我试图捕获我自己的自定义加速器的击键.问题是,如果我将鼠标悬停在根菜单中的子菜单上,我就不会收到任何WM_MENUCHAR消息,而如果我将鼠标悬停在我的子菜单中的子菜单上,那么我就会这样做.
我知道只有有孩子才会发送WM_INITMENUPOPUP消息. WM_MENUCHAR注意到没有加速器绑定到密钥.我知道这个警告是因为当我按下一个键时,我得到了独特的“无加速器”嘟嘟声.
还有另一个我不知道的警告吗?
这是我能够重现问题的最小代码:
HRESULT CFolderViewImplContextMenu::QueryContextMenu(HMENU hmenu, UINT uMenuIndex, UINT idCmdFirst, UINT idCmdLast, UINT /* uFlags */)
{
UINT uID = idCmdFirst;
HMENU hSubmenu = CreatePopupMenu();
MENUITEMINFO mii = { 0 };
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_SUBMENU | MIIM_ID | MIIM_STRING;
mii.dwTypeData = str_toWchar("test");
mii.wID = uID++;
mii.hSubMenu = hSubmenu;
InsertMenuItem ( hmenu, 0, TRUE, &mii );
InsertMenu ( hSubmenu, 0, MF_BYPOSITION, uID++, L"&Notepad" );
InsertMenu ( hSubmenu, 1, MF_BYPOSITION , uID++, L"&Internet Explorer" );
HMENU hSubmenu2 = CreatePopupMenu();
MENUITEMINFO mii2 = {0};
mii2.cbSize = sizeof(MENUITEMINFO);
mii2.fMask = MIIM_ID | MIIM_TYPE | MIIM_SUBMENU;
mii2.fType = MFT_OWNERDRAW;
mii2.wID = uID++;
mii2.hSubMenu = hSubmenu2;
InsertMenuItem ( hSubmenu, 0, TRUE, &mii2 );
InsertMenuA ( hSubmenu2, 0, MF_BYPOSITION, uID++, "");
return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, uID - idCmdFirst );
}
解决方法:
WM_MENUCHAR仅针对子菜单转发. (它不能转发给顶级菜单项,因为那将是一个Catch-22.你想把它转发到键对应的菜单项的上下文菜单处理程序,但你不能这样做直到你得到WM_MENUCHAR的答案!)
标签:windows-shell,explorer,c,windows,winapi 来源: https://codeday.me/bug/20190826/1729354.html