I have a win32 application (C ++) in which the context menu binds to the right button of the notification icon. Menu / submenu items are dynamically created and changed at runtime.
InsertMenu(hSettings, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR) hDevices, L"Setting 1");
InsertMenu(hSettings, 1, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR) hChannels, L"Setting 2");
InsertMenu(hMainMenu, 0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR) hSettings, L"Settings");
InsertMenu(hMainMenu, 1, MF_BYPOSITION | MF_STRING, IDM_EXIT, L"Exit");
In the code above, hDevices and hChannels are dynamically generated submenus. Dynamic menus are created as follows:
InsertMenu(hDevices, i, style, IDM_DEVICE, L"Test 1");
InsertMenu(hDevices, i, style, IDM_DEVICE, L"Test 2");
InsertMenu(hDevices, i, style, IDM_DEVICE, L"Test 3");
Is there a way to find out which item was pressed without giving each item a submenu its own identifier (IDM_DEVICE in the code above)? In would like to find that the user clicked on the IDM_DEVICE submenu and that he clicked on the first item (test 1) in this submenu.
I would like to get something like this:
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_DEVICE:
UINT index = getClickedMenuItem();
break;
}