dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: how to gray a menuitem

  1. #1
    Join Date
    Dec 2009
    Posts
    161

    how to gray a menuitem

    Hi,

    I have a menu with menuitems in a resource.rc file. I load the menu thru the RegisterClassEx and I use the message system thru a callback procedure. I know how to handle messages sent from clicking on a menu item. Yet, I'd like to know ho to gray a menu item by using the SendMessage() function.

    thanks

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: how to gray a menuitem

    You can use ::EnableMenuItem().

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    Dec 2009
    Posts
    161

    Re: how to gray a menuitem

    Ok, but I have some difficulties understanding how to go about using it, the function is:
    Code:
    BOOL EnableMenuItem(      
    	HMENU hMenu,
    	UINT uIDEnableItem,
    	UINT uEnable
    );
    Now, I have the menu defined in an .rc and .h files like the following:
    Code:
    //resource.h
    #define IDM_MENU       200
    #define IDM_FILE_START 201
    #define IDM_FILE_STOP  202
    
    //resource.rc
    #include "resource.h"
    
    IDM_MENU MENU DISCARDABLE
    BEGIN
    	POPUP "&File"
    	BEGIN
    		MENUITEM "Start thread...", IDM_FILE_START
    		MENUITEM "Stop thread...", IDM_FILE_STOP
    	END
    END
    The menu is loaded into the main window thru the WNDCLASS:
    Code:
    .lpszMenuName = MAKEINTRESOURCE(IDM_MENU);
    and I capture the system messages by using the classic window callback:
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch(message)
    	{
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    				case IDM_FILE_START:
    				(...)
    				break;
    
    				case IDM_FILE_STOP:
    				(...)
    				break;
    			}
    			break;
    
    		default:
    		return DefWindowProc(hwnd, Message, wParam, lParam);
    	}
    	return 0;
    }
    Now when I get the IDM_FILE_START wParam thru the WM_COMMAND message how can I disable the IDM_FILE_START menuitem by using the EnableMenuItem() function?

    thanks

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    Re: how to gray a menuitem

    Try to handle WM_INITMENUPOPUP message, if WPARAM is your menu handle - then enable or disable IDM_FILE_START using EnableMenuItem (passing menu handle and menu item ID to it)
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)