Erik

Hi, I have some questions about Menus and the CMenu MFC wrapper class in Visual C++.
First of all I'm using Visual C++ 6.0 in MS Windows XP.
My first question is about the member functions of CMenu: in the MSDN class reference for CMenu its member functions are listed for a certain version of Microsoft Visual Studio. Some of the functions are missing in my compiler: specifically CMenu:Tongue TiedetMenuItem() and CMenu::InsertMenuItem(). Now, my CMenu class has the member function ::GetMenuItem(), so the reason that it doesn't have the corresponding Set function is confusing me. This is not really a problem as I do have the underlying Win32 function SetMenuItem(), but I wonder if I have an older version of the MFC libraries or if there is something wrong here.

The second question is: how do I modify a menu that has been initialized from a resource Is it possible to e.g. change the text on a (sub-) menu item in any menu, or must I maybe create the menu dynamically from the start, not "drawing" it with the resource tool, to be able to dynamically modify it during runtime I try to set the text on a menu item with the CMenu::ModifyMenu() function and SetMenuItem() (as I wrote above I don't have any CMenu:Tongue TiedetMenuItem() in my CMenu class), and I suceed in storing it, but the view is not updated accordingly. I try to apply the DrawMenuBar() to the window but it still doesn't update with the new name string.

Please help
/Erik



Re: Visual C++ General CMenu questions

Bite Qiu - MSFT

Erik wrote:

First of all I'm using Visual C++ 6.0 in MS Windows XP.
My first question is about the member functions of CMenu: in the MSDN class reference for CMenu its member functions are listed for a certain version of Microsoft Visual Studio. Some of the functions are missing in my compiler: specifically CMenu:etMenuItem() and CMenu::InsertMenuItem(). Now, my CMenu class has the member function ::GetMenuItem(), so the reason that it doesn't have the corresponding Set function is confusing me. This is not really a problem as I do have the underlying Win32 function SetMenuItem(), but I wonder if I have an older version of the MFC libraries or if there is something wrong here.

Maybe that reference is not dedicated for the MFC library version that you have, If you are looking at this page, then you can look at the right side of it, it says: "This page is specific to Microsoft Visual Studio 2005/.NET Framework 2.0". MFC libraries usualy ship with visual c++ and its version changes as well, if I recall right, visual c++ 6.0 shipped with mfc version 4.2, in visual c++ 2005 it is mfc version 8.0, so it has been 3 major versions between the document you are reading and the library you actually having. In other word, they could be very different from each other.

Erik wrote:
The second question is: how do I modify a menu that has been initialized from a resource Is it possible to e.g. change the text on a (sub-) menu item in any menu, or must I maybe create the menu dynamically from the start, not "drawing" it with the resource tool, to be able to dynamically modify it during runtime I try to set the text on a menu item with the CMenu::ModifyMenu() function and SetMenuItem() (as I wrote above I don't have any CMenu:etMenuItem() in my CMenu class), and I suceed in storing it, but the view is not updated accordingly. I try to apply the DrawMenuBar() to the window but it still doesn't update with the new name string.

Each resource has an unique ID combined with it, if you want to change the caption of a menu that was created use resource editor, you need to starting from this ID, there are more than one way to do it. The way I prefer is to add message handler for

Code Snippet

UPDATE_COMMAND_UI message:

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
...

ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLBAR, &CMainFrame::OnUpdateViewToolbar)
END_MESSAGE_MAP()

And in the handler you can write something like this:

Code Snippet
void CMainFrame::OnUpdateViewToolbar(CCmdUI *pCmdUI)
{
pCmdUI->SetText(_T("New name"));
}

thanks

Rico