Created the application, turned into the taskbar. Created a context menu from one item, it is successfully called by PCM. Now, I would like to handle clicking on the menu item. Here is the code, but it doesn't work:

case TREY_MESSAGE: // своя константа { switch (lParam) { case WM_RBUTTONUP: { // Извлекаю координаты курсора мыши GetCursorPos(&pt); // т.к. координаты не передаются в функцию, берём напрямую // Отображаем меню TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL); return 0; } case WM_LBUTTONUP: { // щёлчек левой кнопкой мышки return 0; } case WM_COMMAND: { // отладчик здесь не останавливается MessageBoxA(hwnd, "test", "test", MB_OK); if (LOWORD(wParam) == MENU_EXIT) // MENU_EXIT - идентификатор пункта меню PostMessage(hwnd, WM_CLOSE, lParam, wParam); return 0; } default: return 0; } } 

Blocks WM_RBUTTONUP, WM_LBUTTONUP (this one for the test) are processed, but they do not persist in WM_COMMAND. How to treat?

    1 answer 1

    1. You are looking for the WM_COMMAND message not where your operating system can send it. WM_COMMAND is a full-fledged message, whose code is stored in the Msg parameter. You try to work with it as with the code sent within TREY_MESSAGE , looking for it in lParam (like the notification codes in WM_NOTIFY ).

    2. WM_COMMAND checked inside a case working with TREY_MESSAGE , although these are peer messages.