Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


VS2013 Menu Item With Submenus not Disabling/Enabling


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Psychopathetica   Members   -  Reputation: 203

Like
0Likes
Like

Posted 02 May 2014 - 12:28 PM

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 :)



Sponsor:

#2 mark ds   Members   -  Reputation: 1653

Like
0Likes
Like

Posted 02 May 2014 - 12:50 PM

Just a guess, but have you tried disabling all the submenu items?



#3 Buckeye   GDNet+   -  Reputation: 8835

Like
0Likes
Like

Posted 02 May 2014 - 02:31 PM

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, 02 May 2014 - 02:54 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


#4 Psychopathetica   Members   -  Reputation: 203

Like
0Likes
Like

Posted 02 May 2014 - 02:54 PM

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, 02 May 2014 - 03:38 PM.


#5 Endurion   Crossbones+   -  Reputation: 3920

Like
1Likes
Like

Posted 02 May 2014 - 11:25 PM

Do you have maybe colliding menu item IDs? In that case you could try with MF_BYINDEX instead of MF_BYCOMMAND.


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#6 shuma-gorath   Members   -  Reputation: 887

Like
0Likes
Like

Posted 03 May 2014 - 04:44 PM

I've used "MF_BYPOSITION" to do the same thing you're doing and that works.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS