I'm trying to disable/gray out menu items using the CMenu::EnableMenuItem()
method.
I have a CMenu*
variable pMenu
which references the top menu of the dialog. I can get the submenu using pMenu->GetSubMenu(int)
and using submenu->GetMenuStringA()
, verify the names of the submenus/menu items that I get back. I'm having trouble with the EnableMenuItem()
method though. Let's say theres a File
menu. Within it there are New
and Open
popup menus and Import
, Close
, and Close All
menu items. The New
and Open
have submenu items. (e.g New->Document
) Using submenu->EnableMenuItem([position of submenu/menuitem], MF_BYPOSITION | MF_GRAYED);
I can disable New
or Open
, however the function fails for Import
, Close
and Close All
, as well as all the menu items with New
and Open
.
Note: When I say EnableMenuItem()
fails, I don't mean that it returns -1. It returns the previous status, but the menu doesn't become disabled or grayed out.
In the MSDN documentation for EnableMenuItem()
: http://msdn.microsoft.com/en-us/library/h62wh3y1.aspx it claims that this will work for both pop up and standard menu items. It only seems to work for pop up ones, though.