Programming Tips - How do I change a menu from the CMainFrame class of my MDI application?

Date: 2010apr6 Language: C/C++ Platform: Visual C++ Q. How do I change a menu from the CMainFrame class of my MDI application? A. Your generated MFC MDI application has two menus: IDR_MAINFRAME and IDR_MEDIATTYPE. If you do GetMenu() to get a handle in your CMainFrame's OnCreate() member your changes will disappear with the menu is changed to IDR_MEDIATTYPE. The solution is to use ON_UPDATE_COMMAND_UI() like this. In MainFrm.h:
afx_msg void OnUpdateSomething(CCmdUI* pCmdUI);
In MainFrm.cpp:
ON_COMMAND(ID_SOMETHING, OnUpdateSomething) ... void CMainFrame::OnUpdateSomething(CCmdUI* pCmdUI) { if (pCmdUI == NULL) return; ... pCmdUI->SetText("<stuff>"); pCmdUI->Enable(<boolean>); ... }
This is great to modify an individual menu item but if you want to add / delete items it doesn't really work.