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.
clintMonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.