I have implemented an interface IContextMenu3and I am trying to capture keystrokes for my own accelerator. The problem is that if I hover over my submenu in the root menu, I did not receive any messages WM_MENUCHAR, whereas if I hover over a submenu inside one of my submenus, then I will do it.
I know that a message is WM_INITMENUPOPUPsent only if there is a child. WM_MENUCHARhas the reservation that no accelerators are associated with a key. I know that this is a caution to be taken when I press a key, I get a sound “no accelerator”.
Is there another clause that I don't know about?
This is the smallest code I can get that reproduces the problem:
HRESULT CFolderViewImplContextMenu::QueryContextMenu(HMENU hmenu, UINT uMenuIndex, UINT idCmdFirst, UINT idCmdLast, UINT )
{
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 );
}