Advertisement

Another MFC Question (Menus this time)

Started by June 03, 2000 01:57 PM
3 comments, last by Qoy 24 years, 6 months ago
Bah. I have another weird MFC question... I''m trying to enable/disable a menu item on the main menu when something is clicked. Here''s my call: AfxGetMainWnd()->GetMenu()->EnableMenuItem(ID_MENU_ITEM,MF_GRAYED); But the menu item does not appear grayed, and it still works if I click on it. EnableMenuItem is supposed to return the last value for the item''s enabled state, and the first time I call it it returns 0 (MF_ENABLED), and when I call it after I make that call above, it returns MF_GRAYED, so it seems like the message is getting through, just not showing up. Is there something special I have to do in order to make the call actually work?? Thanks!
Gees man, if you''re using MFC, this isn''t hard at all!

You need to handle an ON_UPDATE message. Just go to the Add Message Handler command in MSVC (make sure the View class is selected), find the menu item you want to grey (or un-grey), and add a handler for the ON_UPDATE message, or something similar. Then, in the code block, use pCmdUI->Enable(true) or pCmdUI->Enable(false)



=======================================
A man with no head is still a man.
A head with no man is plain freaky.
Advertisement
Heh. I know it's not *hard* per se

But thanks for the info.

Although I'm still curious as to why the call I made to EnableMenuItem doesn't work... The OnUpdateCmdUI thing seems to give me another way to do it, but this way don't I have to set a boolean for whether or not the menu item should be enabled, and then enable/disable it according to that?

Edited by - Qoy on June 3, 2000 6:15:12 PM
I''m not sure why the other way wouldn''t work, but you really should use the ON_UPDATE type handlers. They are great! If you have toolbar buttons with the same ID as a menu item, then the toolbar buttons will be enabled/disabled at the same time as the menu item. The same thing should work with the status bar panes, too.


- null_pointer
Sabre Multimedia
So how do I use the OnUpdate handler then? I see that it gives me the function, and the function is called whenever I open the menu, but is there a better way to use it than to set a boolean flag for whether or not the item should be enabled, and call pCmdUI->Enable(flag) within OnUpdate?

Basically, I'm wondering how to use the OnUpdate to disable/enable the item when I want it to be enabled/disabled, instead of just when the menu is clicked.

I think I have the wrong idea on how to use it... Could somebody help out? Sorry!

Thanks!

Edited by - Qoy on June 3, 2000 9:23:19 PM

This topic is closed to new replies.

Advertisement