CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Location
    Madrid, Spain
    Posts
    9

    Popup (or Context) Menu

    Hi, I'm working with Visual C++ 6.0 and Directx 8.0 SDK

    I'm making a simple GUI with the Control based in Popup Menus.

    I make a Menu Resource, then load it, then launch it on Right Mouse Button Click. The problem is that i'm not getting the captions of the menu shown. Instead, the menu appears as if my captions where one blank space each. Still i get all the WM_COMMAND message well on each caption, and even popup submenus appear correctly (Opcion4). Any idea in what I might be doing wrong?

    Thx in advance

    Code:
    /**************** RESOURCE.H ********************/
    IDR_MENU MENU DISCARDABLE 
    BEGIN
        MENUITEM "Opcion1",                     IDM_OCION1,
        MENUITEM "Opcion2",                     IDM_OPCION2, CHECKED
        MENUITEM "Opcion3",                     IDM_OPCION3
        POPUP "Opcion4"
        BEGIN
            MENUITEM "Sub1",                        IDM_OPCION4_SUB1
            MENUITEM "Sub2",                        IDM_OPCION4_SUB2
        END
    END
    
    /************* MAINAPP.cpp *******************/
    [...]
    // INIT INSTANCE
    m_hMenuPopup = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU));
    
    [...]
    // MESSAGE LOOP
     case WM_RBUTTONDOWN:
                TrackPopupMenuEx(m_hMenuPopup, TPM_LEFTALIGN, 
                               m_cursor.x, m_cursor.y, hWnd, NULL);
    [...]
    Note: If I append the Captions directly to the Menu, they appear correctly. But I'd like to make the Menus with the resource editor rather that build them line by line in my code

    Code:
    // THIS WORKS
        m_hMenuPopup = CreatePopupMenu();
        AppendMenu(m_hMenuPopup, MF_STRING, 1, "Opcion1");
        AppendMenu(m_hMenuPopup, MF_STRING, 2, "Opcion2");
        AppendMenu(m_hMenuPopup, MF_STRING, 3, "Opcion3");

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Popup (or Context) Menu

    Quote Originally Posted by Comadreja
    The problem is that i'm not getting the captions of the menu shown. Instead, the menu appears as if my captions where one blank space each. Still i get all the WM_COMMAND message well on each caption, and even popup submenus appear correctly (Opcion4). Any idea in what I might be doing wrong?
    When loading a popup menu from a resource, you need to define a top-level, 'dummy' popup menu under which you create the items you want to display. The top level item will never actually show when displaying a popup menu.

  3. #3
    Join Date
    Jul 2004
    Location
    Madrid, Spain
    Posts
    9

    Re: Popup (or Context) Menu

    Thanks a lot!!!! That worked!

    I made the 'dummy' popup menu, then obtained a handle to the submenu and it loaded OK.
    I insert the code working in case it helps someone else

    Code:
    /**************** RESOURCE.H ********************/
    IDR_MENU MENU DISCARDABLE 
    BEGIN
        POPUP "Menu Popup"
        BEGIN
            MENUITEM "Opcion1",                     IDMP_1
            MENUITEM "Opcion2",                     IDMP_2
            MENUITEM "Opcion3",                     IDMP_2
        END
    END
    
    /************* MAINAPP.cpp *******************/
    [...]
    // INIT INSTANCE
    m_hMenuPopup = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU));
    
    [...]
    // MESSAGE LOOP
     case WM_RBUTTONDOWN:
                TrackPopupMenuEx(GetSubMenu(m_hMenuPopup,0), TPM_LEFTALIGN,
                               m_cursor.x, m_cursor.y, hWnd, NULL);
    [...]
    What I still don't understand is why the captions didn't appear without the 'dummy menu'. It might be because it is a popup menu?? And if so, why appending the captions directly in the code worked well?


    Nevermind, if it works it works!

    Now I'm getting into a new question: is there any function to easily change the captions of the menu without affecting its IDs? I'm thinking of multi-language GUI, and a way to load all the new captions from a file when changing the language. I'm investigating the InsertMenuItem function but it don't find a way to just replace the caption without changing anything else. Any idea on this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured