Disable a Menu Item

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,
For this MFC app that I am maintaining there is a menu item that I
would like to disabled, grey-out, at runtime if a certian condition is
met. From reading previous posts on similar questions I have tried,

CMenu *pMenu = GetMenu();
pMenu->EnableMenuItem(ID_SEARCH_TRUCK_INFO, MF_GRAYED |
MF_BYCOMMAND);

This compiles and runs but does not do anything.

In another post I came across it was suggested to do the below. How is
the code below actually used? Called?

void CMainFrame::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
/*
bool bEnable = ... ; true if it need to enable menu item
or false othewise.
bool bCheck = ... ;
*/


// ...


pCmdUI->Enable(bEnable); // if needed
pCmdUI->SetCheck(bCheck); // if needed
pCmdUI->SetText("Text"); // if needed
}


Thanks
Jeff
.



Relevant Pages

  • Re: Disable a Menu Item
    ... For this MFC app that I am maintaining there is a menu item that I ... would like to disabled, grey-out, at runtime if a certian condition is ... From reading previous posts on similar questions I have tried, ... Use this approach if you are using doc/view, because it overrides anything you try and do with CMenu functions. ...
    (microsoft.public.vc.mfc)
  • Re: Disable a Menu Item
    ... scottmcp> wrote: ... For this MFC app that I am maintaining there is a menu item that I ... would like to disabled, grey-out, at runtime if a certian condition is ...
    (microsoft.public.vc.mfc)