C++/VB - how to gray a menu item
Asked By Larry
08-Feb-10 09:11 AM

Hi,
I have some difficulties understanding how to go about using
EnableMenuItem() function (I need to gray a menuitem)
BOOL EnableMenuItem(
HMENU hMenu,
UINT uIDEnableItem,
UINT uEnable
);
Now, I have the menu defined in an .rc and .h files like the following:
//resource.h
//resource.rc
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:
.lpszMenuName = MAKEINTRESOURCE(IDM_MENU);
and I capture the system messages by using the classic window callback:
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
UIDEnableItem
(1)
EnableMenuItem
(1)
DefWindowProc
(1)
LpszMenuName
(1)
WndProc
(1)
GetMenu
(1)
UEnable
(1)
MAKEINTRESOURCE
(1)
David Lowndes replied to Larry
What exactly are you having difficulties with?
Have you tried something like:
EnableMenuItem( GetMenu( hWnd ),
IDM_FILE_START,
MF_GRAYED | MF_BYCOMMAND );
Dave
return DefWindowProc (hwnd, message, wParam, lParam);Try to find above C++ / VB return DefWindowProc (hwnd, message, wParam, lParam); Try to find above function return what value is it in integer or string or boolean VC Language Discussions Return (1) DefWindowProc (1) Message (1) WParam (1) LParam (1) Function (1) Value (1) Integer (1 DefWindowProc and WndProc both return LRESULT, that's no problem. I'm suspecting this is occurring or else use ExitProcess instead of return. Either one will eliminate the warning. keywords: return, DefWindowProc, (hwnd, , message, , wParam, , lParam);Try, to, find, above description: return DefWindowProc (hwnd, message, wParam, lParam); Try to find above function return what value is it in
does this code not work in my dialog application: CMenu *pMenu = ::AfxGetMainWnd()-> GetSystemMenu(false); pMenu-> EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); pMenu-> EnableMenuItem(SC_MINIMIZE, MF_BYCOMMAND | MF_GRAYED); pMenu-> EnableMenuItem(SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED); It only disables and greys out the close button and not the solution, but not the one I really wanted. Z.K. VC MFC Discussions AfxGetMainWnd (1) EnableMenuItem (1) SetWindowLong (1) GetSystemMenu (1) GetWindowLong (1) CMenu (1) PMenu (1) HWnd (1) I have does this code not work in my dialog application: CMenu *pMenu = ::AfxGetMainWnd()-GetSystemMenu(false); pMenu-EnableMenuItem(SC_CLOSE, MF_BYCOMMA
C++ CMenu EnableMenuItem not working C++ / VB C++, VS .NET 2003, MFC I have a tray app where disabled even though in the property pages in resource editor states enabled. I use the EnableMenuItem method of the CMenu object and set one of them to enabled. This works, however this on only one menu item, and not both? THanks. VC MFC Discussions OnUpdateUI (1) EnableMenuItem (1) CFrameWnd (1) CMenu (1) Newcomer (1) Overridden (1) Starters (1) Handlers (1) I believe takes over the task of updating menu items, defeating anything you try to do with EnableMenuItem. In this situation you control menu enables by adding OnUpdateUI message handlers. - - Scott McPhillips [MVP items using ON_UPDATE_COMMAND_UI handler. A dialog app is not derived from CFrameWnd and will honor EnableMenuItem if its the owner of the menu. - -- Ajay Since you show no code, it is http: / / www.flounder.com MVP Tips: http: / / www.flounder.com / mvp_tips.htm keywords: C++, CMenu, EnableMenuItem, not, working description: C++, VS .NET 2003, MFC I have a tray app where right