Sign in to follow this  
xytor

[Win32] Get pointer to a top menu item?

Recommended Posts

xytor    136
Quote:
Original post by SiCrane
You can use the EnableMenuItem() function.


That function is great, but how do I use it for a menu item that has a sub-menu? For example, I can easily gray-out "Open", but how can I gray-out "File"?

Share this post


Link to post
Share on other sites
ApochPiQ    23064
There's one thing you should know about the way menus work in Windows: there's no special distinction between a "top level" menu and a "sub menu". The menu "bar" is actually a menu just like every other: each entry is a menu item with optional sub-menus. The fact that it is rendered horizontally instead of vertically is purely aesthetic.

So, for example, File, Window, Help, etc. are all just menu items in a menu; just as New, Save, and Exit are menu items under a menu. Therefore you can use EnableMenuItem() to do what you want, given the correct handle [smile]

Share this post


Link to post
Share on other sites
xytor    136
Quote:
Original post by ApochPiQ
There's one thing you should know about the way menus work in Windows: there's no special distinction between a "top level" menu and a "sub menu". The menu "bar" is actually a menu just like every other: each entry is a menu item with optional sub-menus. The fact that it is rendered horizontally instead of vertically is purely aesthetic.

So, for example, File, Window, Help, etc. are all just menu items in a menu; just as New, Save, and Exit are menu items under a menu. Therefore you can use EnableMenuItem() to do what you want, given the correct handle [smile]


Right, but unlike the individual menu items, the top-level menu items don't have an id in resource.h. I have ID_FILE_OPEN40001 but not something like ID_FILE.

Share this post


Link to post
Share on other sites
xytor    136
Quote:
Original post by Erik Rufelt
Many menu functions have flags where you can specify MF_BYPOSITION to give it the index of the menu-item instead of the ID.


Hmm, I don't know if that applies here. I finally hacked it into working by doing this:
EnableMenuItem(GetMenu(hWnd),(unsigned int)(unsigned __int64)GetSubMenu(GetMenu(hWnd),3),MF_GRAYED);

I wonder if that is bad... lol

Share this post


Link to post
Share on other sites
xytor    136
OOOH ok, now I understand. Thank you all very much!

By the way, I was using msdn, but it's kind of hard to find anything if you don't know what you're looking for. For example, this is what it showed me first: http://msdn.microsoft.com/en-us/library/aa984351(VS.71).aspx

Share this post


Link to post
Share on other sites
Flimflam    665
Quote:
Original post by xytor
OOOH ok, now I understand. Thank you all very much!

By the way, I was using msdn, but it's kind of hard to find anything if you don't know what you're looking for. For example, this is what it showed me first: http://msdn.microsoft.com/en-us/library/aa984351(VS.71).aspx


Keep in mind that says Windows Forms on that page. You're trying to do it in pure Win32.

Windows Forms is the managed framework designed around Win32 for writing .NET applications.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this