Click to See Complete Forum and Search --> : Popup (or Context) Menu


Comadreja
December 2nd, 2004, 04:11 AM
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


/**************** 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


// 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");

gstercken
December 2nd, 2004, 04:33 AM
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.

Comadreja
December 2nd, 2004, 04:56 AM
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


/**************** 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! :rolleyes:

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?