Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » CExtToolControlBar Collapse All
Subject Author Date
Paolo Giustinoni Aug 29, 2006 - 5:59 AM

How to disable or enable programmatically a button in a CExtToolControlBar?

Suhai Gyorgy Aug 29, 2006 - 6:19 AM

With MFC’s command UI updating mechanism.

In MainFrm.h:

afx_msg void OnUpdateYourCommand(CCmdUI* pCmdUI);
In your Message map you have to have an entry like:
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	...
	ON_UPDATE_COMMAND_UI(ID_YOUR_COMMAND, OnUpdateYourCommand)
	...
END_MESSAGE_MAP()

In MainFrm.cpp
void CMainFrame::OnUpdateColorSilver(CCmdUI* pCmdUI) 
{
	if (bSomeCondition)
		pCmdUI->Enable(false);
}

Suhai Gyorgy Aug 29, 2006 - 6:21 AM

Sorry, I posted without finishing up properly. Last method should be called OnUpdateYourCommand.
And one more thing you have to be careful with: This OnUpdateYourCommand method gets called very-very often, so don’t put any lengthy operation in it.

Paolo Giustinoni Aug 29, 2006 - 6:32 AM

The CExtToolControlBar is in a dialog box, so this mechanism don’t apply here.
I have to disable or enable a button via some function like EnableButton or similar..

Thanks

Suhai Gyorgy Aug 29, 2006 - 7:05 AM

The mechanism still applies, but instead of MainFrm files, you have to put the code in your application’s main dialog class.
I did try to find another way to disable button before, but it didn’t work out for me.

Paolo Giustinoni Aug 29, 2006 - 7:47 AM

It’s OK now! Thanks