How to put a tick in a windows menu?

This is a discussion on How to put a tick in a windows menu? within the Windows Programming forums, part of the Platform Specific Boards category; Hi all, My program minimises to the SystemTray and i have created a menu that when i right click on ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    100

    How to put a tick in a windows menu?

    Hi all,

    My program minimises to the SystemTray and i have created a menu that when i right click on the icon in the system tray it popsup. This works fine. Now what I want to do is when the user clicks on one of the options in the menu i want a tick to be put next to it. I have managed to do this using a normal menu on a window but no matter what I try I cannot get it working on the system tray menu. Can you spot what i am doing wrong?

    First is my Menu found in Resource.rc

    Code:
    IDR_POPUP MENU
    BEGIN
        POPUP "File"
        BEGIN
            MENUITEM "Open",                        ID_MENU_OPEN
            MENUITEM SEPARATOR
            MENUITEM "All Security",                ID_MENU_ALL
            MENUITEM "Custom Security",            	ID_MENU_CUSTOM
            MENUITEM "No Security",                 ID_MENU_NONE
            MENUITEM SEPARATOR
            MENUITEM "Exit",                        ID_MENU_EXIT
        END
    END
    Now is the code im trying to get to work

    Code:
    //Get Menu associated with hwnd
    HMENU lMainSystemMenu = LoadMenu(hwnd, MAKEINTRESOURCE(IDR_POPUP));
    // HMENU lSystemTrayPopupMenu = GetSubMenu(lMainSystemMenu, 0); commented out due to also doesnt work
    
    // check that both lMainSystemMenu and lSystemTrayPopupMenu are valid menus 	
    if(!IsMenu(lMainSystemMenu) /* || !IsMenu(lSystemTrayPopupMenu */)
    	ASSERT(false);
    
    // Modify menu and assert if failed
    if(!ModifyMenu(lMainSystemMenu, ID_MENU_ALL, MF_CHECKED, ID_MENU_ALL, "All" ))
        ASSERT(false);
    	
    DrawMenuBar(hwnd);
    This code compiles fine and even runs without asserting however the item ID_MENU_ALL does not get checked.

    You can see that there is a commented out HMENU called lSystemTrayPopupMenu. When that is uncommented and ModifyMenu uses that as its first parameter everything compiled fine but still remains unchecked.

    Thanks for any help, this is driving me up the wall

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Your ModifyMenu parameters seem to be incorrect - the third parameter should be a set of OR'd flags that determine both the action to be taken and whether your menu item is identified by position or identifier. See the remarks section for ModifyMenu for more details.

    A simpler approach would be to use CheckMenuItem, although you should be aware that SetMenuItemInfo should be preferred over either function.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  2. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 10:59 AM
  3. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  4. Delet Frequency in linked list
    By swishiat.com in forum C Programming
    Replies: 16
    Last Post: 12-13-2003, 02:05 AM
  5. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 03:58 AM

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