Jump to content
  • Advertisement
Sign in to follow this  
Ataru

MFC onUpdate Toolbars

This topic is 5072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don't know MFC at all, but I've been forced to do a little of it. Generally everything is clear, except for one thing. Say I have a button, that is sometimes grayed sometimes not, it's on the toolbar. I added it to the menu as well, and created both a "COMMAND" and "UPDATE_COMMAND_UI" method. And implemented it properly to check/gray as desired. My problem is, that unless I access the menu, the toolbar icon will not automatically gray. The reason is because onUpdate gets called when I access the menu. How do I handle greying of buttons on my toolbar though? I can check the status every frame and update it manually, but I don't even know how to manually gray a specific button in MFC. Any help is appreciated, thannks.

Share this post


Link to post
Share on other sites
Advertisement
To grey out a toolbar button with id ID_TOOLBAR_BUTTON you would do:

CToolbar *Toolbar = ...;
Toolbar->GetToolBarCtrl().SetState(ID_TOOBLAR_BUTTON, TBSTATE_INDETERMINATE);







It seems like you are using the ON_UPDATE_COMMAND_UI handlers the wrong way. Make two separate update functions, one for your menu and one for your toolbar button.

ON_UPDATE_COMMAND_UI(ID_MENU, UpdateMenu)
ON_UPDATE_COMMAND_UI(ID_TOOLBAR_BUTTON, UpdateToolbarButton)

void UpdateMenu(CCmdUI *CmdUI)
{
CmdUI->Enable(/* put your expression for when the menu should be enabled here */);
}

void UpdateToolbarButton(CCmdUI *CmdUI)
{
CmdUI->Enable(/* put your expression for when the toolbar button should be enabled here */);
}






Use the ON_UPDATE_COMMAND_UI() functionality if you can, and avoid setting them explicitly. Then your application does not have to account for when to enable/disable gui items. MFC will call your update functions when it has idle time over.

Hope this helped. I know how frustrating MFC can be sometimes.

[Edited by - doho on September 3, 2004 3:03:14 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!