Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

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.
0
clintMon
Asked:
clintMon
  • 3
  • 3
1 Solution
 
itsmeandnobodyelseCommented:
>>>> I've created a popup menu

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




0
 
clintMonAuthor Commented:
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.

0
 
itsmeandnobodyelseCommented:
>>>> 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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
clintMonAuthor Commented:
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.
0
 
itsmeandnobodyelseCommented:
Why didn't you change the labels by calling

      pMenu->ModifyMenu(item, ..);

If you create a menu in a handler function there is no way that UPDATE_UI notifications could be sent to your window class. There isn't any connection between both objects. The MFC framework works differently. When creating a frame window via dialog templates, the menu id was passed at creation time. Then, notifications can be setup and were periodically processed by the message loop at idle times.

Regards, Alex
0
 
clintMonAuthor Commented:
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");

}

 
 
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now