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 Tech Support » How to disable and gray a specified button on toolbar Collapse All
Subject Author Date
delu qiu May 9, 2006 - 9:01 AM

Hi,

How to disable and gray a specified button on toolbar?

Thanks

Technical Support May 10, 2006 - 4:22 AM

The toolbar window is based on MFC’s command updating mechanism. Therefore add command updating methods for command buttons in your toolbar and use the CCmdUI::Enable() method for changing command states. If you need a toolbar which is not based on the command updating, use a CExtToolControlBar-derived class which overrides the CExtToolControlBar::OnUpdateCmdUI() virtual method. Your method should have an empty body. This custom toolbar will never update states of its buttons and you have to access the CExtBarButton objects using the CExtToolControlBar::GetButtonsCount() and CExtToolControlBar::GetButton() methods. The state of each CExtBarButton object can be changed if you apply or remove the TBBS_DISABLED style using the CExtBarButton::ModifyStyle() method. You can get the button styles with the CExtBarButton::GetStyle() method.

Suhai Gyorgy May 10, 2006 - 1:54 AM

As you’d do in any MFC application:

In your MainFrm.h:

afx_msg void OnUpdateMyCommand(CCmdUI* pCmdUI);

In your MainFrm.cpp:

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
...
ON_UPDATE_COMMAND_UI(ID_OF_MY_COMMAND, OnUpdateMyCommand)
...
END_MESSAGE_MAP()

void CMainFrame::OnUpdateMyCommand(CCmdUI *pCmdUI)
{
if ( some_condition )
pCmdUI->Enable(false);
else
pCmdUI->Enable(true);
}

Actually you could put that also in your view class (I think), but usually it’s in MainFrm.
And of course this will disable not only the toolbar button, but also the menu entry connected to this ID.

Hope that helps:
Chris.

delu qiu May 12, 2006 - 9:55 AM

It’s work perfectly, Thanks a lot.