Sign in to follow this  

VS2013 Menu Item With Submenus not Disabling/Enabling

This topic is 1355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been stuck on this all day yesterday, and yes, I can enable and disable menu items in my Win32 window, as well as submenu items, but not menu items that contain submenus, which are menu items with a > symbol. I tried different combinations, and nothing works to disable or enable menu items that contain submenus. Not even this:

 


HMENU menu = GetMenu(hWnd);
HMENU submenu = GetSubMenu(menu, 0);
EnableMenuItem(submenu, ID_FILE_LOADSTATE, MF_BYCOMMAND | MF_GRAYED);
DrawMenuBar(hWnd);

Is there a way to do it on menu items that contain submenus? Thanks in advance :)

Share this post


Link to post
Share on other sites

EDIT: Sorry. This is incorrect.

>> No - MF_GRAYED is not a proper argument. You need to use MF_CHECKED or MF_UNCHECKED.

 

It's generally easier to use:

HMENU menu = GetMenu(hWnd); // do you check that for a valid return?
CheckMenuItem( menu, ID_FILE_LOADSTATE, MF_BYCOMMAND | MF_UNCHECKED);

That can be generalized. For instance, you may have a true/false flag bCanLoadState. Then you can use:

CheckMenuItem( menu, ID_FILE_LOADSTATE, MF_BYCOMMAND | (bCanLoadState? MF_CHECKED : MF_UNCHECKED));

EDIT: and this doesn't do what you want, either. You want to gray the item, not check or uncheck.

 

Do you check valid return values for your function calls? I.e., are you getting the main window menu handle okay? and the submenu handle?

 

EDIT2: You aren't by any chance using a floating menu bar are you? GetMenu doesn't work with floating menu bars.

Edited by Buckeye

Share this post


Link to post
Share on other sites

Well im not checking or unchecking menu item. Im enabling and disabling, as in greying or ungreying a menu item that contains submenus. It works on menu items by them selves and submenus, but not menu items that contain submenus.

 

And I know it works, because like I said in the first post, it works great on menu items and submenu items, even without using GetSubMenu(). But it does not work on menu items with the (>) symbol that contain submenus. Its very strange as to why it doesn't. I'm not using a floating menu bar. More like a menu created from a resource.

Edited by Psychopathetica

Share this post


Link to post
Share on other sites
Sign in to follow this