Prev: How to get handle to context menu of grouped application in taskbar
Next: ImageList + extract image
From: Larry on 8 Feb 2010 09:11 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 #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: ..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
From: r_z_aret on 8 Feb 2010 10:31 On Mon, 8 Feb 2010 15:11:27 +0100, "Larry" <dontmewithme(a)got.it> wrote: >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 >#define IDM_MENU 200 >#define IDM_FILE_START 201 >#define IDM_FILE_STOP 202 > clip > >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? In the following, hMenu is the HMENU for the main window and nPosMenu is the position (in that main menu) for the menu containing the item your want to change. To enable: HMENU hMenuSub = GetSubMenu( hMenu, nPosMenu ); UINT uFlag = MF_ENABLED | MF_BYCOMMAND; BOOL bResult = EnableMenuItem( hMenuSub, IDM_FILE_START, uFlag ); The MF_BYCOMMAND indicates that IDM_FILE_START is a control ID, rather than the item position. > >thanks ----------------------------------------- To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message). Robert E. Zaret, eMVP PenFact, Inc. 20 Park Plaza, Suite 400 Boston, MA 02116 www.penfact.com Useful reading (be sure to read its disclaimer first): http://catb.org/~esr/faqs/smart-questions.html
From: Paul N on 11 Feb 2010 17:01 On 8 Feb, 15:31, r_z_aret(a)pen_fact.com wrote: > On Mon, 8 Feb 2010 15:11:27 +0100, "Larry" <dontmewit...(a)got.it> > wrote: > > 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 > >#define IDM_MENU 200 > >#define IDM_FILE_START 201 > >#define IDM_FILE_STOP 202 > > > >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? > > In the following, hMenu is the HMENU for the main window and nPosMenu > is the position (in that main menu) for the menu containing the item > your want to change. > > To enable: > > HMENU hMenuSub = GetSubMenu( hMenu, nPosMenu ); > UINT uFlag = MF_ENABLED | MF_BYCOMMAND; > BOOL bResult = EnableMenuItem( hMenuSub, IDM_FILE_START, > uFlag ); > > The MF_BYCOMMAND indicates that IDM_FILE_START is a control ID, rather > than the item position. According to MSDN, it will look for the command to alter in any submenus of the given menu. So, unless you have the same command in more than one submenu, you don't need to use GetSubMenu. For instance, I have just tried: HMENU hMenu = GetMenu(hWnd); EnableMenuItem(hMenu, IDM_LOAD, MF_GRAYED | MF_BYCOMMAND); EnableMenuItem(hMenu, IDM_HIDE, MF_GRAYED | MF_BYCOMMAND); and it sucessfully grayed out items in two different submenus. Hope this helps. Paul.
|
Pages: 1 Prev: How to get handle to context menu of grouped application in taskbar Next: ImageList + extract image |