I would like to add the context menu / submenu of the context menu to my win32 application (C ++) when the user right-clicks on notifiyicon data (tray icon). I can make a simple level 1 menu, but I cannot find an example for a menu with several levels.
I would like to create a menu that looks something like this:
Settings -> Setting 1 -> Setting 2 -> Setting 3 -> Settings 4 -> Setting 5 -> Setting 6 Exit
I am creating a menu using this code:
HMENU hPopupMenu = CreatePopupMenu(); InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, IDM_EXIT, L"Exit"); SetForegroundWindow(hWnd); TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_RIGHTALIGN, px, py, 0, hWnd, NULL);
The above code is placed inside the notifyicondata message handler (WM_RBUTTONUP).
How can I create a submenu using the above code? Create a new HMENU and paste it into the parent menu?
Another thing that bothers me is that the menu is always created when the right-click event is fired, so every time it fires, a new HMENU is created. Is it possible to create a menu (with a submenu) when starting the application and destroy it when closing the application? Do windows handle menu destruction?
Thanks for the answer.
source share