Thread: Graying and Ungraying menu items

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    39

    Question Graying and Ungraying menu items

    How can I make it so that a menu item starts out grayed, but then when two variables are at a certain value, it becomes ungrayed and accessable?

    I am using Dev C++
    Platform: Windows XP

  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Code:
    if( !SomethingOrOther)
    	{
    		EnableMenuItem(hMenu, IDM_FILE_EDIT, MF_GRAYED);
    	}
    	else
    	{
    		EnableMenuItem(hMenu, IDM_FILE_EDIT, MF_ENABLED);
    		
    	}
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  3. #3
    Registered User joed's Avatar
    Join Date
    Mar 2004
    Posts
    59
    EnableMenuItem function lets you enable, disable, or gray out an item.

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    39
    I tried that, but I get the error that hMenu is undeclared. What is supposed to be there? Sorry if this seems obvious to you, I'm not the best at this .

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Well naturally, you need to supply the handle of your menu, you may not call it hMenu.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User
    Join Date
    Apr 2005
    Posts
    39
    Quote Originally Posted by adrianxw
    Well naturally, you need to supply the handle of your menu, you may not call it hMenu.
    Sorry if I'm sounding silly...but what do you mean?

  7. #7
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    You need to look up 'LoadMenu'.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  8. #8
    Registered User
    Join Date
    Apr 2005
    Posts
    39
    Quote Originally Posted by Bajanine
    You need to look up 'LoadMenu'.
    Would you mind elaborating on that a bit? That doesn't help me at all.

  9. #9
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Did you try to look it up? MSDN

    What exactly have you tried?
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If I say use......

    HMENU hMenu=GetMenu(hWnd);

    will you ask what hWnd is?
    "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

  11. #11
    Registered User
    Join Date
    Apr 2005
    Posts
    39
    Look, I am not as good as you people at this.

    I found the LoadMenu line in my code...

    Code:
    SetMenu(hwnd,LoadMenu(hinstance, "MYMENU"));
    ...and I tried everything from it, but nothing is working. So if you people are just saying simply one sentence, then it's not going to help much.

    So, what do I put instead of hMenu?

  12. #12
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    Code:
    HMENU hMenu = GetMenu ( hWnd ) ;
    if ( ucGreyItem )
        EnableMenuItem ( hMenu, YOUR_ITEMS_UNIQUE_ID_OR_INDEX, MF_GREYED | MF_DISABLED ) ;
    else
        EnableMenuItem ( hMenu, YOUR_ITEMS_UNIQUE_ID_OR_INDEX, MF_ENABLED ) ;
    See EnableMenuItem for details

Popular pages Recent additions subscribe to a feed