Jump to content
  • Advertisement
Sign in to follow this  
CDProp

Silly MFC problem (enabling/disabling menu items)

This topic is 4213 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I wish to enable and disable items in my dialog's main menu (File, Edit, View, etc.) depending on the circumstance. I get the File Menu's object like this:
CMenu *MainMenu		= AfxGetApp()->m_pMainWnd->GetMenu();
CMenu *pFileMenu	= MainMenu->GetSubMenu( 0 );
Since File is the first menu on the list, this should get the object for me. I set a breakpoint here to verify that pFileMenu is not NULL after this funciton is called, and indeed it is not. So, to disable a menu item, I do the following:
UINT result	= pFileMenu->EnableMenuItem( ID_FILE_MENUITEM, MF_BYCOMMAND | MF_GRAYED);
I set a break point here, and the result IS valid. However, when I hit F5 to resume execution of the program, and then look at the menu item, it is not grayed out like it is supposed to be. Does anyone know what I'm doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Where are you attempting to modify the menu?

Look into processing this message -> ON_WM_INITMENUPOPUP

void YourWindow::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
//Modify the menu before it is shown.
}

Share this post


Link to post
Share on other sites
I was attempting to do it from the view class (derived from CFormView). Could that be the problem? The reason I did that is that I need to access information in the document in order to determine whether certain options should be enabled or disabled. The only way I know how to access the document, outside of the document itself, is to called GetDocument() from the view that is associated with it.

Share this post


Link to post
Share on other sites
Hmm, Can you processes that message in a CView, I dont remember if views get the menu messages. Try doing it from your mainframe and query the current view for details from there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!