how can i check a menuitem with a V on the left of it, like so many apps do?
thank you.
Printable View
how can i check a menuitem with a V on the left of it, like so many apps do?
thank you.
For resources: MENUITEM Statement
For code: Menus
gg
it returns MF_UNCHECKED, but doesn't check the item, why is that?Code:CheckMenuItem(LoadMenu(ghInstance, MAKEINTRESOURCE(ID_MENU)), IDM_SETTINGS_GROUP, MF_CHECKED);
Use GetMenu to get a handle to the window menu and GetSubMenu for any of that menu's submenus.
this code now returns an error that the menuitem could not be found?Code:CheckMenuItem(GetMenu(hwnd), IDM_SETTINGS_GROUP, MF_CHECKED)
can you please explain the idea behind submenus, maybe i need to use them...
Quote:
Originally Posted by Devil Panter
Please read, in particular, the 'about menus' section and then take another look at the descriptions for CheckMenuItem, GetMenu and GetSubMenu.Quote:
Originally Posted by Codeplug
I now understand what a position is but i still don't understand where i use it, or should i say how i use it...
i need a position of 3:2, which is the IDM_SETTINGS_GROUP.
can you please give me an example, because i'm really lost hereCode:CheckMenuItem(GetSubMenu(hwnd, 3), IDM_SETTINGS_GROUP, MF_BYPOSITION | MF_CHECKED);
You're almost there but the first parameter of GetSubMenu is an HMENU.orCode:/*only works if IDM_SETTINGS_GROUP is the position of the menu item and NOT its id*/
CheckMenuItem(GetSubMenu(GetMenu(hwnd), 3), IDM_SETTINGS_GROUP, MF_BYPOSITION | MF_CHECKED);
Code:/*only works if IDM_SETTINGS_GROUP is the id of the menu item and NOT its position*/
CheckMenuItem(GetSubMenu(GetMenu(hwnd), 3), IDM_SETTINGS_GROUP, MF_BYCOMMAND | MF_CHECKED);
the IDM_SETTINGS_GROUP is an idetifier of the menuitem...
i tried both ways, it still gives me an error that the menuitem could not be found.
btw, you meant:
andCode:/*only works if IDM_SETTINGS_GROUP is the position of the menu item and NOT its id*/
CheckMenuItem(GetSubMenu(GetMenu(hwnd), 3), IDM_SETTINGS_GROUP, MF_BYPOSITION | MF_CHECKED);
Code:/*only works if IDM_SETTINGS_GROUP is the id of the menu item and NOT its position*/
CheckMenuItem(GetSubMenu(GetMenu(hwnd), 3), IDM_SETTINGS_GROUP, MF_BYCOMMAND | MF_CHECKED);
>>btw, you meant:<<
Thanks, yes I did. :rolleyes: Sorry about that.
[edit]Fixed now.[/edit]
>>still gives me an error<<
Is your menu item a submenu item of a submenu item of a submenu item...etc? If so, you'll have to keep using GetSubMenu item in an analgous way to get a valid menu handle.
If not then it might be a good idea to post some more code.
If i'm not mistaken i have a simple submenu item, but just in case:
http://thedp.netfirms.com/a.html
about posting more code, this is it, what else can i post everything else is not related.
Then this should work:assuming that IDM_SETTINGS_GROUP is the id for that particular menu item.Code:CheckMenuItem(GetSubMenu(GetMenu(hwnd), 3), IDM_SETTINGS_GROUP, MF_BYCOMMAND | MF_CHECKED);
Where in your code are you calling CheckMenuItem? WM_COMMAND handler? Is CheckMenuItem actually being called? Return value of CheckMenuItem?
>>what else can i post everything else is not related<<
If all else fails then create a window with the same menu and see if you can replicate the problem with that simplified, cut-down version. If you still encounter the same problem with the simplified test example then post the code for it.
i thought so... it doesn't work :(
i'm calling the CheckMenuItem from WM_CREATE.
and it returns -1 --> menuitem not found.
Did you try this? Is this what "it doesn't work" is referring to? If so, post that code or zip up and attach it.Quote:
If all else fails then create a window with the same menu and see if you can replicate the problem with that simplified, cut-down version.
i tried something else:
i loaded the menu from the resource, and it returned a good value: MF_UNCHECKEDCode:CheckMenuItem(GetSubMenu(LoadMenu(ghInstance, MAKEINTRESOURCE(ID_MENU)), 3), IDM_SETTINGS_GROUP, MF_CHECKED)
but still nothing changed...
i guess i'll do what you said, and post a full code tomorrow.
thanks.