Re: Disable/gray Menu, not menu item
On Fri, 06 Apr 2007 20:39:48 -0500, Mike M <nospam@nospam.com> wrote:
I'd like to disable and gray out a menu. Not an item on
a menu, but the menu "button" itself. Like the "File", or
"Edit" menu on the main frame menu window of a CDialog.
In certain states I'd like to gray it out and disable it.
Is there a way to do this?
Some would say not to do this, because it interferes with command
discoverability. Note that you will also need to disable all the commands
reachable from the menu. This is necessary for toolbar buttons to reflect
the program state, and I believe it's also necessary to eliminate the
possibility of reacting to someone posting a raw WM_COMMAND. Macros such as
ON_UPDATE_COMMAND_UI_RANGE can help you avoid implementing update handlers
for every menu item, and if the status of several menu items with
non-sequential IDs depends on the same criteria, you can map them to the
same update handler. If you're really in a pinch, you can override OnCmdMsg
and handle things there. It's important to leverage the MFC "update-UI"
mechanism for two reasons: 1. It ensures visible representations of the
command (menu items, toolbar buttons) reflect the command state, and 2. MFC
uses this mechanism to test the status of a command before executing it.
--
Doug Harrison
Visual C++ MVP