• Advertisement
Sign in to follow this  

[Win32] Get pointer to a top menu item?

This topic is 2687 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

Is there a function that gives me a pointer to an item on the top menu? For example, "File" or "Edit".

Share this post


Link to post
Share on other sites
Advertisement
That gives me a handle, not a pointer with which I could call menuItem->enabled = true;

Share this post


Link to post
Share on other sites
There's no such thing in straight Win32 code. You need to work with the handle.

Share this post


Link to post
Share on other sites
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
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
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
Many menu functions have flags where you can specify MF_BYPOSITION to give it the index of the menu-item instead of the ID.

Share this post


Link to post
Share on other sites
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
Just use 3 for the uIDEnableItem and use MF_BYPOSITION | MF_GRAYED for uEnable.

Share this post


Link to post
Share on other sites
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
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
Sign in to follow this  

  • Advertisement