I created a context menu using CreatePopupMenu(). I then added menu entries using InsertMenu(..), displayed it with TrackPopupMenu(..).
A few questions:
-
Where do the window messages get sent when I click on something in the context menu? The MSDN docs do a great job of explaining how to create a context menu, but once you have it I’m unsure of how to handle it.
-
The docs specify that I need to call DestroyMenu(HMENU hMenu) after TrackPopupMenu. I’ve written that into my app, but I don’t quite understand what’s going on here. If I just created a menu, wouldn’t DestroyMenu() destroy it? In other words, what is it destroying?
When you click an item in the popup menu, the operating system will send a
WM_COMMANDmessage to the window that ‘owns’ the popup menu, that is, more specifically, to the window you specified in your call toTrackPopupMenu(thehWndparameter).When you create a menu, the operating system will reserve memory to store information about the menu. When you no longer need the menu (when you know you will never display it again), you can free this memory by calling
DestroyMenu.