Thread: Can a menu POPUP have an ID?

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    161

    Can a menu POPUP have an ID?

    I've tried giving an ID to a menu popup in my resource file, but it never seems to work. I'm trying to come up with a way to automate something I do repeatedly with different parts of the menu. I'll post some source below with a comment as to what I'm wanting to accomplish.

    p.s. Why can't you use control styles like LVS_EX_GRIDLINES in the damn resource file instead of having to SendMessage LVM_SETEXTENDEDLISTVIEWSTYLE them?

    Code:
    //This is a piece of the menu as an example...
    RENEGADE_MNU MENU
    BEGIN
    	POPUP "File"
      	BEGIN
        	MENUITEM "Exit",MNU_EXIT
      	END
    	POPUP "Search"
      	BEGIN
      		POPUP "Input Type"
        	BEGIN
        		MENUITEM "Hexadecimal",MNU_CS_INPUT_HEX
          		MENUITEM "Decimal",MNU_CS_INPUT_DEC
          		MENUITEM "Float/Double",MNU_CS_INPUT_FLOAT
        	END
      		MENUITEM "Load Search",MNU_CS_LOAD_SEARCH
        	MENUITEM "Undo Last Search",MNU_CS_UNDO
    	END
    END
     //then within the message loop at WM_COMMAND
    //Notice how I have to uncheck them all a line at a time. If I could grab the popup, 
    //I should be able to call a little function to loop and uncheck them for less clutter in my source.
    
    			    case MNU_CS_INPUT_HEX: case MNU_CS_INPUT_DEC: case MNU_CS_INPUT_FLOAT:
                    {
                        Settings.CS.NumBase = GetMenuItemData(hMenu, LOWORD(wParam));
                        Settings.CS.NumBaseId = LOWORD(wParam);
                        SetMenuState(hMenu, MNU_CS_INPUT_HEX, MFS_UNCHECKED);
                        SetMenuState(hMenu, MNU_CS_INPUT_DEC, MFS_UNCHECKED);
                        SetMenuState(hMenu, MNU_CS_INPUT_FLOAT, MFS_UNCHECKED);
                        SetMenuState(hMenu, LOWORD(wParam), MFS_CHECKED);
                    } break;
    
    //SetMenuState does exactly what it sounds like. It's a wrapper for the standard SetMenuInfo function
    //I didn't want to spend 5 lines doing that all the time either.
    int SetMenuState(HMENU hMenu, UINT id, UINT state)
    {
        MENUITEMINFO mnuItem; memset(&mnuItem,0,sizeof(mnuItem));
        mnuItem.cbSize = sizeof(MENUITEMINFO);
        mnuItem.fMask = MIIM_STATE;
        mnuItem.fState = state;
        return SetMenuItemInfo(hMenu, id, FALSE, &mnuItem);
    }
    Last edited by Viper187; 03-02-2010 at 03:48 PM.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by Viper187 View Post
    I've tried giving an ID to a menu popup in my resource file, but it never seems to work.
    Popups don't have a handler as clicking on them only draws the actual popup menu (the user then clicks on one of these items to generate the msg).

    You could try owner draw but this would be lots of work for little reward.

    You could also save the last checked item so next time the user clicks on the menu you could just uncheck the previous item (if any) then check the new selection.

    Quote Originally Posted by Viper187 View Post
    Why can't you use control styles like LVS_EX_GRIDLINES in the damn resource file instead of having to SendMessage LVM_SETEXTENDEDLISTVIEWSTYLE them?
    Guessing....

    Extended styles are a relatively new addition (if you remember DOS and Win95...)

    To maintain backwards compatibiltity and MS had used up all the bits available with the standard styles.

    (ie when first created MS used a 32 bit variable to hold the style flags.
    MS added more styles.
    Because there are now more than 32 styles MS had to add another 32 bit flag to hold the newer styles.
    MS could not make the original 32 bit flag bigger as that would break all the old code.)
    Last edited by novacain; 03-08-2010 at 12:45 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. popup menu in MFC?
    By Robert602 in forum Windows Programming
    Replies: 7
    Last Post: 07-25-2007, 09:34 PM
  4. TreeView + Popup menu
    By JaWiB in forum Windows Programming
    Replies: 9
    Last Post: 02-17-2006, 01:56 AM
  5. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM