menu items check

This is a discussion on menu items check within the Windows Programming forums, part of the Platform Specific Boards category; how can i check a menuitem with a V on the left of it, like so many apps do? thank ...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    menu items check

    how can i check a menuitem with a V on the left of it, like so many apps do?


    thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,648
    For resources: MENUITEM Statement
    For code: Menus

    gg

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Code:
    CheckMenuItem(LoadMenu(ghInstance, MAKEINTRESOURCE(ID_MENU)), IDM_SETTINGS_GROUP, MF_CHECKED);
    it returns MF_UNCHECKED, but doesn't check the item, why is that?
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Use GetMenu to get a handle to the window menu and GetSubMenu for any of that menu's submenus.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Code:
    CheckMenuItem(GetMenu(hwnd), IDM_SETTINGS_GROUP, MF_CHECKED)
    this code now returns an error that the menuitem could not be found?

    can you please explain the idea behind submenus, maybe i need to use them...
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by Devil Panter
    can you please explain
    ...
    Quote Originally Posted by Codeplug
    For code: Menus

    gg
    Please read, in particular, the 'about menus' section and then take another look at the descriptions for CheckMenuItem, GetMenu and GetSubMenu.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    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.

    Code:
    CheckMenuItem(GetSubMenu(hwnd, 3), IDM_SETTINGS_GROUP, MF_BYPOSITION | MF_CHECKED);
    can you please give me an example, because i'm really lost here
    Last edited by Devil Panther; 12-09-2004 at 07:54 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You're almost there but the first parameter of GetSubMenu is an HMENU.
    Code:
    /*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);
    or
    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);
    Last edited by Ken Fitlike; 12-09-2004 at 12:44 PM. Reason: corrected typos spotted by Devil Panther (see folowing post)
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    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:
    Code:
    /*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);
    and
    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);
    Last edited by Devil Panther; 12-09-2004 at 08:52 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>btw, you meant:<<

    Thanks, yes I did. 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.
    Last edited by Ken Fitlike; 12-09-2004 at 12:44 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  11. #11
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    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.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Then this should work:
    Code:
    CheckMenuItem(GetSubMenu(GetMenu(hwnd), 3), IDM_SETTINGS_GROUP, MF_BYCOMMAND | MF_CHECKED);
    assuming that IDM_SETTINGS_GROUP is the id for that particular menu item.

    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  13. #13
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    i thought so... it doesn't work

    i'm calling the CheckMenuItem from WM_CREATE.
    and it returns -1 --> menuitem not found.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  14. #14
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.
    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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  15. #15
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    i tried something else:
    Code:
    CheckMenuItem(GetSubMenu(LoadMenu(ghInstance, MAKEINTRESOURCE(ID_MENU)), 3), IDM_SETTINGS_GROUP, MF_CHECKED)
    i loaded the menu from the resource, and it returned a good value: MF_UNCHECKED
    but still nothing changed...


    i guess i'll do what you said, and post a full code tomorrow.

    thanks.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. MFC check box question
    By MyglyMP2 in forum Windows Programming
    Replies: 2
    Last Post: 03-09-2009, 05:47 PM
  3. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  5. Disable menu items.
    By Bajanine in forum Windows Programming
    Replies: 4
    Last Post: 05-14-2004, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21