Enabling Menu Item in Main Menu? 
Author Message
 Enabling Menu Item in Main Menu?

I am trying to enable a menu item in the main menu bar.
I have a created a handler for the menu item and have tried to call pMenu->EnableMenuItem(itemID, MF_BYCOMMAND|MF_GRAYED); and this doesn't seem to work.  However, calling pMenu->CheckMenuItem(itemID, MF_BYCOMMAND, MF_CHECKED) will put a checkmark next to the menu item.
I know this is a simple problem, please enlighten me with a possible solution?
Thanks,
Roberto

-----------------** -- Posted from CodeGuru -- **-----------------
http://www.*-*-*.com/ ;  The website for Visual C++ programmers.



Fri, 19 Oct 2001 03:00:00 GMT  
 Enabling Menu Item in Main Menu?

Quote:

>I am trying to enable a menu item in the main menu bar.
>I have a created a handler for the menu item and have tried to call
>pMenu->EnableMenuItem(itemID, MF_BYCOMMAND|MF_GRAYED); and this doesn't
>seem to work.  However, calling pMenu->CheckMenuItem(itemID, MF_BYCOMMAND,
>MF_CHECKED) will put a checkmark next to the menu item.
>I know this is a simple problem, please enlighten me with a possible solution?

     What you're trying to do is correct for a regular Win32 app; but it's
swimming against the current in MFC.
     You've presumably already added an ON_COMMAND handler to your app for
the menu item you're trying to manage; you should add an ON_UPDATE_COMMAND_UI
handler as well.  That handler will get called whenever a menu containing
that command is about to be displayed; it can enable/disable and check/uncheck
the command as appropriate.
     The huge advantage to managing commands with ON_UPDATE_COMMAND_UI
handlers, rather than trying to do it yourself, is that the handler is much
more flexible.  For example, if you later decide to add that same command to
a toolbar, the same handler that enables/disables the menu will automatically
enable/disable the toolbar button as well.  If you decide to add context
menus to your application, and that same command appears on one of your
context menus, the handler will automatically work there too.  You can turn
off MFC's menu-managing mechanism and do it yourself the way you're trying to
do now; but if you do, then you'd have to add code to manage your toolbars and
context menus in the same way, which winds up being much more complex than
letting MFC take care of it.

--
\o\ If you're interested in books and stories with transformation themes, \o\
/o/ please have a look at <URL:http://www.halcyon.com/phaedrus>. Thanks!  /o/
\o\   FC1.21:FC(W/C)p6arw A- C->++ D>++ H+ M>+ P R T++++ W** Z+ Sm RLCT   \o\
/o/              a cmn++++$ d e++ f+++ h- i++wf p-- sm#                   /o/



Fri, 19 Oct 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to disable/enable Popup menu item of the main menu

2. Enabling/Disabling Menu items for a menu on a dialog application

3. Enable and Disable Menu Items

4. WTL: Enabling and disabling menu items

5. How to disable/enable menu item?

6. How to disable.enable menu item?

7. Enable/Disable of top-level menu items

8. Context menu item disable/enable

9. How to enable menu items?

10. PROBLEM IN MENU ITEM DISABLING ENABLING

11. The trick to getting items in dynamic menus enabled

12. Enable/Disable menu items dynamically (last question)

 

 
Powered by phpBB® Forum Software