Question

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

Was it helpful?

Solution

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);
}

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top