Jump to content
  • Advertisement
Sign in to follow this  
maxest

winapi - menu and MF_CHECKED

This topic is 4629 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 create a menu. i want one of my items be checked/unchecked. i may set an item as checked only when i create my menu:
void form_render_createMenu(HWND hwnd)
{
        ...

	AppendMenu(sub_menu, MF_POPUP | MF_CHECKED, 8, "Nadrzędna siatka");

        ...

and i want to change this state during program's work. how can i do that? is this possible to send some message to the item to set it checked or sth? or maybe i need to create menu every time when the state must be changed? (but that'd be very tragical idea i think...)

Share this post


Link to post
Share on other sites
Advertisement
It's rather simple:


MENUITEMINFO mii;

mii.fMask = MII_STATE;
// hMenuHandle is the handle to the popup window the Menu item is on.
// MenuItemId is the id of the menu item.
GetMenuItemInfo(hMenuHandle, MenuItemId, FALSE, &mii);

mii.fMask ^= MFS_CHECKED;
// hMenuHandle is the handle to the popup window the Menu item is on.
// MenuItemId is the id of the menu item.
SetMenuItemInfo(hMenuHandle, MenuItemId, FALSE, &mii);




The above code (plug in your variables for hMenuHandle and MenuItemId) will flag the check box on the associated menu item on and off each time it's called.

Share this post


Link to post
Share on other sites
your code has some mistakes. i used it as a template and i changed a little:


MENUITEMINFO menu_item_info;
menu_item_info.cbSize=sizeof(MENUITEMINFO);

menu_item_info.fMask=MIIM_STATE;
GetMenuItemInfo(sub_menu_of_map_designer, 3, TRUE, &menu_item_info);

menu_item_info.fState^=MFS_CHECKED;
SetMenuItemInfo(sub_menu_of_map_designer, 3, TRUE, &menu_item_info);




first of all, you forgot to set cbSize. second of all, not MII_STATE, but MIIM_STATE. and not MENUITEMINFO.fMask^=MFS_CHECKED but MENUITEMINFO.fState^=MFS_CHECKED is correct :) and one more, not FALSE in ...MenuItemInfo but TRUE ;)
great thx for the idea with ^. it is very useful

Share this post


Link to post
Share on other sites
but with lovely MSDN (one of few microsoft's good things :D) i solved my problem. however, without your reply i would be stucked, so thx for the help :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!