Re: Disable a Menu Item
On Nov 28, 1:18 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-
scottmcp> wrote:
"Hoop" <jcoll...@oshtruck.com> wrote in message
news:b88588cb-870a-43f0-bbf4-ccf458d713f8@r60g2000hsc.googlegroups.com...
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
Your second example, OnUpdate...., is a feature of the MFC document/view
architecture framework. The OnUpdate... functions are called just before
the menu is displayed, and/or during idle time. Use this approach if you
are using doc/view, because it overrides anything you try and do with CMenu
functions.
--
Scott McPhillips [VC++ MVP]- Hide quoted text -
- Show quoted text -
Hi Scott,
I am using doc/view. So I would add something like,
afx_msg void OnUpdateMenuItem(CCmdUI* pCmdUI);
and the method definition, as in my first post.
How I would actually call this, as a function call, without a message
map entry, or do I need that?
The argument CCmdUI, not sure what I would put in there.
Thanks
Jeff