CodeMaster12 CodeMaster12 - 1 year ago 47
C Question

Win32 Shortcut Menu doesn't send messages in any case

I have a shortcut menu that I display but no matter what I do with it, it doesn't send any messages.

I tried it in a high level mouse hook, tried it in WM_CONTEXTMENU window procedure message. No matter what I will do, what I return, it never sends a message.

The menu is created during application launch, destroyed when application is closing down.

Here is the menu creation code:

DoomRatGUI_SlavesListItemMenu = CreatePopupMenu();
DoomRatGUI_SlavesListItemMenuInfo = calloc(1, sizeof(MENUINFO));
DoomRatGUI_SlavesListItemMenuInfo->fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
DoomRatGUI_SlavesListItemMenuInfo->cbSize = sizeof(MENUINFO);
DoomRatGUI_SlavesListItemMenuInfo->dwStyle = MNS_NOCHECK | MNS_NOTIFYBYPOS;
//DoomRatGUI_SlavesListItemMenuInfo->hbrBack = ResourcesManager_GetDarkGreyBrush();
SetMenuInfo(DoomRatGUI_SlavesListItemMenu, DoomRatGUI_SlavesListItemMenuInfo);
AppendMenuW(DoomRatGUI_SlavesListItemMenu, MF_STRING, 1001, L"Actions");
AppendMenuW(DoomRatGUI_SlavesListItemMenu, MF_STRING, 1002, L"Quick Info");
AppendMenuW(DoomRatGUI_SlavesListItemMenu, MF_STRING, 1003, L"Quick Stop");
AppendMenuW(DoomRatGUI_SlavesListItemMenu, MF_STRING, 1004, L"Quick Restart");

I show the menu using the line of code:


If you know a solution tell me what I have to do because I have tried everything, like... where to put that piece of code exactly, Thanks.

PS: DoomRAT isn't anything malicious, its a tiny 2D game I am working on for learning.

Answer Source

The TPM_RETURNCMD flag causes TrackPopupMenu to return the chosen menu item id as the functions return value instead of sending a WM_COMMAND message.

Also, allocating MENUINFO like that is unnecessary, it is a small struct, just use the stack.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download