Archived

This topic is now archived and is closed to further replies.

Qoy

UPDATE_COMMAND_UI

Recommended Posts

In my level editor, I need to disable or enable a menu item based on whether a certain index is selected in a list box. The standard method of getting a pointer and calling EnableMenuItem with the item ID didn''t work, so some people pointed me to the UPDATE_COMMAND_UI message. Here''s how I''m using it: In the OnSelChange function for my list box, depending on what is being selected, I am setting a boolean to either true or false. Then in the OnUpdateUI function for the menu item, I am calling pCmdUI->Enable() with that boolean variable as a parameter, to enable or disable the window as needed. Is this the correct way to use that message/function? To me, it seems like this has to enable/disable it every time the menu is brought down, which seems sort of inefficient, so I thought I''d ask if there are better ways to use it.. Thanks for the help!

Share this post


Link to post
Share on other sites

in my level editor, the way i handled my UPDATE_COMMAND_UI was doing the standard classwizard messages and doing an if statement inside of them. you could do something like this instead:


(inside OnUpdate function)
if(selection == 1)
{
pCmdUI->Enable();
}
else if
{
pCmdUI->Enable(FALSE);
}


the way you are doing it would work, too, i assume. normally when you have a command mapped to a menu item, MFC enables the menu item automatically. i don''t know why the command wouldn''t disable.... try it my way and see if it works, and if not, then send me your code and i''ll do all that i can to help.

david

Share this post


Link to post
Share on other sites
i''m not sure EXACTLY how the mfc architecture works, but simply calling
pCmdUI->Enable( bEnabled );
each time the menu is opened, doesn''t seem like a big hit. it''s in a level editor anyway. but you are correct in the usage.


crazy166
some people think i'm crazy, some people know it

Share this post


Link to post
Share on other sites
I agree with crazy166. Besides, pCmdUI->Enable() probably just sets some bool flag inside MFC anyway. If you want to step through it, the MFC source code is there -- just step into the function with VC''s debugger.

And if it turns out to be a performance hog, use another bool to track the previous value. If the previous value is different from the new value, you call pCmdUI->Enable(). Otherwise, the call is redundant.





- null_pointer
Sabre Multimedia

Share this post


Link to post
Share on other sites
well how bout this:

i have a dynamic menu created every time the user right-clicks inside of my map editor to where it displays and allows the user to select from a list of dynamically loaded tile bits that are loaded on startup. every time the user right-clicks, i have a for loop that appends the bit names to the certain menu. the menu displays fine, it''s just that i can get the stupid menu items to check! i''ve tried calling the popup menu''s SetCheck function and that didn''t work. i also tried calling an UpdateCommandRangeUI and that didn''t seem to work either. i know i had it all set up right, i just don''t know why it doesn''t want to take my check marks!

any help would be greatly appreciated...

david

Share this post


Link to post
Share on other sites
I think SetCheck() should work. Are you re-creating your popup window every time you display it? Then it would definitely not store the check state between calls. Then perhaps you could make the popup menu a data member of your mainframe or view class, and simply show or hide it when you need it.

Usually, a popup menu is just a collection of the same menu items (and the same IDs) from the program''s main menu, so calling pCmdUI->SetCheck() on an UPDATE_COMMAND_UI for your main menu items should do the trick.





- null_pointer
Sabre Multimedia

Share this post


Link to post
Share on other sites