Friday, June 11, 2010

How to disable menu items in VC++

How to disable a menu item in VC++?



afx_msg void OnUpdateXXX(CCmdUI* pCmdUI);



void CXXXXXX::OnUpdateXXX(CCmdUI *pCmdUI)




NOTE: the following doesnot work properly:

CWnd* pParent = GetParent(); // This is a point to the window
CMenu* pMenu = pParent->GetMenu();
pMenu->EnableMenuItem(ID_NEW_WO , MF_GRAYED );

The effects of EnableMenuItem are preempted by the actions of the menu
update handlers. For example, if you use EnableMenuItem() to disable a
menu item, the default menu update handler will reenable it if an
ON_COMMAND macro is defined for that item. This, off course, negates
the effect of your attempt to disable it. To eanable or disable a menu
item, you should provide your own menu update handler and then use the
Enable() member function of CCmdUI.

No comments: