views:

1145

answers:

2

How can I hide a menu item under certain conditions in MFC?
I'm not interested in just graying it out.

+5  A: 

Add an Update Handler for your menu item (using ON_UPDATE_COMMAND_UI).

This line should appear in your message map:

  ON_UPDATE_COMMAND_UI(ID_MYMENUITEM, OnUpdateMyMenuItem)

In the handler, use this code:

void CMainFrame::OnUpdateMyMenuItem(CCmdUI *pCmdUI)
{
  if (pCmdUI->m_pMenu!=NULL)
    pCmdUI->m_pMenu->DeleteMenu(pCmdUI->m_nID, MF_BYCOMMAND);
}
Serge - appTranslator
+2  A: 

Or if you are removing a single menu item use CMenu::RemoveMenu

Shane MacLaughlin