我有一個win32應用程序(C++),它有一個上下文菜單綁定到通知圖標上的右鍵單擊。菜單/子菜單項是在運行時動態創建和更改的。C++ win32動態菜單 - 哪個菜單項被選中
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");
在上面的代碼中,hDevices和hChannels是動態生成的子菜單。 動態菜單像這樣產生的:
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");
是否有被點擊,而不必限定每個子菜單項它自己的ID(IDM_DEVICE在上面的代碼中),其項知道的方法嗎?在想要檢測到用戶點擊了子菜單IDM_DEVICE並且他點擊了該子菜單中的第一項(測試1)。
我想才達到這樣的事:
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_DEVICE: // user clicked on Test 1 or Test 2 or Test 3
UINT index = getClickedMenuItem(); // get the index number of the clicked item (if you clicked on Test 1 it would be 0,..)
// change the style of the menu item with that index
break;
}
謝謝我一直在搜索一個樣本,找不到任何! – blejzz