In our project, there are two menus defined in our rc file, with the names IDR_MAINFRAME AND IDR_MDICHILD. Both of them have the submenu 'Help' and its items defined separately. Now based on a condition in the registry, we want to change a word in both Help menu items - say "About old App" to "About new App" . Now, I could easily change the text in the main help menu(IDR_MAINFRAME), but even after trying a lot, the text in the mdi menu is not getting changed.
Description- this is how I have changed the mainframe menu text in the OnCreate() method of mainframe: (which is the method for event WM_CREATE of CMainFrame.)
menu.ModifyMenuW(ID_HELP_TOPICS, MF_BYCOMMAND | MF_STRING, ID_HELP_TOPICS, newMenuString); //newMenuString contains the changed string
But for the mdi window, even if I'm able to access the menu string and seemingly changing it, it is not getting reflected on the display.
I am doing it in the event implementation of WM_MDISETMENU (or WM_MDIGETACTIVE , none of them working). This is the code I wrote:
LRESULT CMainFrame::OnMDISetMenu(UINT, WPARAM wParam, LPARAM, BOOL& bHandled)
BOOL result = menu2.LoadMenuW(IDR_MDICHILD); //result returns 1, that means the call was successful.
CMenuHandle menu(menu2.GetSubMenu(4)); // 4 is the id of Help menu in my case.
menu.ModifyMenuW(ID_HELP_TOPICS, MF_BYCOMMAND|MF_STRING, ID_HELP_TOPICS, newMenuString);//assume newMenuString contains the proper new text.
mMDIWnd.DefWindowProc(); //I tried moving this call before the text changing stuff
If I get the menu string again using the GetMenuString() method in the same function, I know that it does change the text, but I don't know why it is not getting displayed on the showed up menu?
Like WM_MDISETMENU, I also defined the handler for the event WM_INITMENUPOPUP, and in that also I'm changing the text of the mdi_child help menu (same way shown above), but none of them is getting reflected when it shows up.
Derive from CUpdateUI<CMainFrame> add your ID_HELP_TOPICS in the UPDATE_UI_MAP, and call UISetText(ID_HELP_TOPICS, _T("Whatever")) to change the menu text with that ID on all menus.
Your problem may come from Unicode MBCS mismatch, or the Help menu position changing with the Windows menu being or not inserted ...
Anyhow CUpdateUI usage will make your code much simpler.
Thanks for your reply. Good that our code was already having ID_HELP_TOPICS in the update_ui_map. But where do you think I should call the UISetText()? I tried it in all the event handlers I could write it in : for WM_INIT_MENUPOPUP, WM_CREATE, WM_MDIREFRESHMENU, WM_MDISETMENU, WM_MDIGETACTIVE, .... but none of them is working.
Infact with ModifyMenuW() I can change the text of the main frame Help Menu properly, but if I use UISetText(), it doesn't even change that. What wrong do you think I might be doing?
See http://www.codeproject.com/KB/wtl/wtl4mfc2.aspx#uiupdating for CUpdateUI usage.
CUpdateUI Base uses WM_INITMENUPOPUP for its purpose, so if you have a handler for this message set bHandled to FALSE to allow processing in the chained message map.