Grey out the menu in MFC

I am trying to grey out the submenu item if a flag is set to false.

how do i acheive this ? Can anyone send a snippet please



ON_COMMAND(ID_TOOLS_DELETECURVES, OnToolsDelete)

void XgView::OnToolsDelete()
{
  XgDeleteDlg Cdlg(AGROUP);

      if (Cdlg.DoModal() == IDOK) {}
}
hari4130Asked:
Who is Participating?
 
AxterConnect With a Mentor Commented:
You can disable a menu item via following method:

CMenu* pMenu = GetMenu();
 pMenu->EnableMenuItem(ID_FILE_NEW,MF_GRAYED);

However, I recommend you use the ON_UPDATE_COMMAND_UI MFC macro to do this
0
 
AxterCommented:
To use the ON_UPDATE_COMMAND_UI MFC macro, select the view in ClassWizard, select the menu item (ID_FILE_NEW or whatever), and create a handle for ON_UPDATE_COMMAND_UI.
0
 
AxterCommented:
Here's example code for your ON_UPDATE_COMMAND_UI function:

void CMainFrame::OnUpdateCommand...(CCmdUI* pCmdUI)
{
     pCmdUI->Enable(bEnableThisMenuItem );    
}

In above example function, bEnableThisMenuItem is a member BOOL variable you create to enable or disable your menu item.
0
 
NawalKishore1976Commented:
Hi either use the OnUpdate or Modify Menu

void CMainFrame::OnUpdateFileTest(CCmdUI* pCmdUI)
{
      pCmdUI->Enable(FALSE);

      //ModifyMenu(hMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED, SC_CLOSE, "Close")
      
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.