Sign in to follow this  
Ataru

MFC onUpdate Toolbars

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this