MFC Menu Graying.
-
Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.
-
Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.
Try using the method EnableMenuItem() with nEnable set to MF_GRAYED. From the docs: ============================= CMenu::EnableMenuItem UINT EnableMenuItem( UINT nIDEnableItem, UINT nEnable ); MF_GRAYED Disables the menu item so that it cannot be selected and dims it. ============================= For this to work, you'll need to use CMenu classes for your menus and not just resource menus. If you don't want to use CMenu, then you can gray menus by using the SDK call EnableMenuItem: ============================= The EnableMenuItem function enables, disables, or grays the specified menu item. BOOL EnableMenuItem( HMENU hMenu, // handle to menu UINT uIDEnableItem, // menu item to enable, disable, or gray UINT uEnable // menu item flags ); =============================
-
Try using the method EnableMenuItem() with nEnable set to MF_GRAYED. From the docs: ============================= CMenu::EnableMenuItem UINT EnableMenuItem( UINT nIDEnableItem, UINT nEnable ); MF_GRAYED Disables the menu item so that it cannot be selected and dims it. ============================= For this to work, you'll need to use CMenu classes for your menus and not just resource menus. If you don't want to use CMenu, then you can gray menus by using the SDK call EnableMenuItem: ============================= The EnableMenuItem function enables, disables, or grays the specified menu item. BOOL EnableMenuItem( HMENU hMenu, // handle to menu UINT uIDEnableItem, // menu item to enable, disable, or gray UINT uEnable // menu item flags ); =============================
-
Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.
This is an unusual question, because MFC atomaticaly grays submenus until the use specifies a handler or explicitly says not to gray it. The question why is the menue item grayed is far more commond (a good thing). One of the great things about using MFC class wizard it that you do not need to know the details (although you should). When you bring up the class wizard it gives you a chance to specify a handler to use when you select an item (menu/button/etc..) as well as wheather it is enable or not. INTP
-
This is an unusual question, because MFC atomaticaly grays submenus until the use specifies a handler or explicitly says not to gray it. The question why is the menue item grayed is far more commond (a good thing). One of the great things about using MFC class wizard it that you do not need to know the details (although you should). When you bring up the class wizard it gives you a chance to specify a handler to use when you select an item (menu/button/etc..) as well as wheather it is enable or not. INTP
-
Hi there everyone. I am new to MFC application programming. I was just wondering how do i gray a submenu during runtime? For instance like Microsoft Visual C++, you'll need to open up a workspace before the File>Close Workspace will be active. Otherwise it will still stay grayed.
The normal MFC way of enabling/disabling menu items during runtime is to implement the UPDATE_COMMAND_UI handler for the item. To do this, use the class wizard to add an UPDATE_COMMAND_UI message handler for the particular menu item that you want to handle: - On the "Message Maps" page, select the object id of the menu item that you want to control - select the UPDATE_COMMAND_UI in the Messages window. - Click on the "Add Function" button to add a handler for it. - Click on the "Edit Code" button to goto the code for the newly added handler. In the handler code, you can control whether the menu item is enabled or disabled as follows: - To enable the menu item, call pCmdUI->Enable( TRUE ); - To disable the menu item, call pCmdUI->Enable( FALSE );