6

Here is what it is doing

I am trying to load a popup "right click" menu, and use the resource file to define the menu items. The picture shows what is happening when I right click, it displays room for 2 items, which is correct, but doesnt show any text.

In the .cpp:

POINT pt;
pt.x = LOWORD (lParam);
pt.y = HIWORD (lParam);
ClientToScreen (hwnd, &pt);
HMENU hMenu = LoadMenu(NULL, MAKEINTRESOURCE(IDR_POPUPMENU));
TrackPopupMenu (hMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL);

and the resource:

IDR_POPUPMENU MENU DISCARDABLE 
BEGIN
MENUITEM "test",              IDM_TEST
MENUITEM "Close",               IDM_CLOSE
END

any idea on what I am donig wrong?

Thanks.

EDIT: I just tested, and clicking in the "no text displayed" areas, and it sends the correct message. What could be causing it to not display the text?

2 Answers 2

13

Found the solution:

HMENU hMenu = LoadMenu(NULL, MAKEINTRESOURCE(IDR_POPUPMENU));
hMenu = GetSubMenu(hMenu, 0);

and resource:

IDR_POPUPMENU MENU DISCARDABLE 
BEGIN 
   POPUP "TEST" 
      BEGIN     
        MENUITEM "Test",                IDM_TEST
        MENUITEM "Close",               IDM_CLOSE
      END
END

Just had to start the resource entry with a beginning sub menu, TEST does not display, only its menu items do.

1
  • SO is the real WinAPI documentation
    – M.M
    Apr 29, 2021 at 0:39
5

Your menu resource is incorrect. It must be a popupmenu. eg:

IDR_MENU_TRAY MENU
BEGIN
    POPUP "ContextMenu"
    BEGIN
        MENUITEM "ShowWindow",                  ID_POPUP_SHOWWINDOW
        MENUITEM "Exit",                        ID_POPUP_EXIT
    END
END

TrackPopupMenu first parameter is a handle to a submenu associated with an existing menu item. You can see the examples here: http://msdn.microsoft.com/EN-US/library/ms647558(v=VS.85,d=hv.2).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.