Dana
Dana

Reputation: 2739

Hiding a menu item in MFC

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

Upvotes: 11

Views: 17803

Answers (2)

SmacL
SmacL

Reputation: 22922

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

Upvotes: 3

Serge Wautier
Serge Wautier

Reputation: 21878

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

Upvotes: 19

Related Questions