Dave's Brain

Browse - programming tips - modify menu from cmainframe mdi

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 modify an individual menu item but you want to
add / delete items its doesn't really work.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.