Jump to content
  • Advertisement
Sign in to follow this  
CTEagle

Enable\Disable Menu Items

This topic is 4147 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 have a form with a menu on the top. How can I Enable\Disable these items during runtime? For instance how would I enable enable "File-Save" after the user has made a change to a document? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
You can use the EnableMenuItem function to enable/disable a Menu Item. You'll have to pass it a handle to the menu that owns the item. In case of the File/Save menu entry you'll need a handle to the File sub-menu. Here is a small sample code:

// get a handle to the windows menu bar
HMENU hMainMenu = GetMenu(hWnd);

// get a handle to the file submenu (assuming that File is the first entry in the menu bar)
HMENU hSubMenu = GetSubMenu(hMainMenu, 0);

// disable save item (assuming it has ID_FILE_SAVE as the menu item id)
EnableMenuItem(hSubMenu, ID_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED);


EnableMenuItem either takes the menu item ID (as in my example) or the item's position in the menu. You can choose which one you specify by either using MF_BYCOMMAND (=ID) or MF_BYPOSITION (= zero-based position).

Hope that helps!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!