clintMon
asked on
Changing text of a menu item
In design time, i've created a popup menu. This menu has several menu items on it. One of these menu items (PopupA) is marked as "Popup" in it's property pages, so it spawns a submenu. When PopupA is selected, a submenu is launched (which is also created at design time). I need to dynamically change the text of one of these submenu items. What I've done so far is add the following message map: ON_UPDATE_COMMAND_UI(ID_MY _MENU_ITEM , OnUpdateMyMenuItem). In this function (OnUpdateMyMenuItem), I change the menu item text.
PROBLEM IS, my function (OnUpdateMyMenuItem) never gets called. I've put a stop in there and ran in debug mode, and this function never gets called. Any thoughts?
clint
FYI, the window in which I launch this menu is an openGL window.
PROBLEM IS, my function (OnUpdateMyMenuItem) never gets called. I've put a stop in there and ran in debug mode, and this function never gets called. Any thoughts?
clint
FYI, the window in which I launch this menu is an openGL window.
ASKER
I have the following message back declared in my openGL window's header file:
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
So when I right click in my openGL window, the OnContextMenu function gets called, and my design time created popup menu, which we'll call ID_DESIGNTIME_POPUP_MENU, displays in the window.
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
So when I right click in my openGL window, the OnContextMenu function gets called, and my design time created popup menu, which we'll call ID_DESIGNTIME_POPUP_MENU, displays in the window.
>>>> and my design time created popup menu, which we'll call ID_DESIGNTIME_POPUP_MENU, displays in the window.
Could you post the code that creates (invokes) the menu? Obviously the OnContextMenu function is just a handler of the right-click event but the menu functionality needs to be implemented seperately.
Regards, Alex
Could you post the code that creates (invokes) the menu? Obviously the OnContextMenu function is just a handler of the right-click event but the menu functionality needs to be implemented seperately.
Regards, Alex
ASKER
In OnContextMenu(...), I've got the following code to create the popup menu:
CMenu* pMenu = new CMenu;
pMenu->LoadMenu (ID_DESIGNTIME_POPUP_MENU) ;
CMenu* pPopUpMenu = pMenu->GetSubMenu(0);
ID_DESIGNTIME_POPUP_MENU has been created in design time, using the resource wizard.
CMenu* pMenu = new CMenu;
pMenu->LoadMenu (ID_DESIGNTIME_POPUP_MENU)
CMenu* pPopUpMenu = pMenu->GetSubMenu(0);
ID_DESIGNTIME_POPUP_MENU has been created in design time, using the resource wizard.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THANK YOU. Yep, didn't even think about pMenu->ModifyMenu(item, ..); Hadn't actually used that function before. So, for anyone who wants to know, to simply change text menu item from a menu created in the resource editor, just do the following:
OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu* pMenu = new CMenu;
pMenu->LoadMenu (ID_MY_POPUP_MENU); //associate a pointer to the design-time created menu
CMenu* pSubMenu = pMenu->GetSubMenu(0); //point to the submenu
//change the text of the menu item
pSubMenu->ModifyMenu(ID_OF _MENU_ITEM , MF_STRING, ID_OF_MENU_ITEM, "Hi Mom");
}
OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu* pMenu = new CMenu;
pMenu->LoadMenu (ID_MY_POPUP_MENU); //associate a pointer to the design-time created menu
CMenu* pSubMenu = pMenu->GetSubMenu(0); //point to the submenu
//change the text of the menu item
pSubMenu->ModifyMenu(ID_OF
}
What do you call a popup menu? Did you associate the menu to a CFrameWnd? Or how do you invoke the menu?
>>>> What I've done so far is add the following message map
Message maps only work within the MFC framework. If you have an active view class derived from CView notification messages like the ON_UPDATE_COMMAND_UI notification were sent for the active menu and it's menu items only. The active menu is determined by the current dialog or view or the current frame window associated to the view. Also the document and application class in a SDI or MDI architecure can be targets of menu messages.
I don't know whether it is possible (or senseful) to adopt the ON_UPDATE_COMMAND_UI mechanism of the MFC framework to parts that were outside of the framework, e. g. the OpenGL window you were talking of. If you are creating a CMenu object from a resource, it might be easier to change the menu item names at creation time by calling ModifyMenu. Or you might call ModifyMenu in an event handler of your dialog (or view) class, where the menu should be stored as a member.
Regards, Alex