0
votes

I have created MFC based application Visual Studio 2010 Professional Edition, where I have created my own class(CMToolBar) derive from CToolbar and I am using the CMToolbar class object in a dialog based application.

In its create function , by default I am trying to disable the states of few buttons, but as soon I used the code such as :-

 GetToolBarCtrl().EnableButton(ID_ONE,false);

or

this->SendMessage(TB_ENABLEBUTTON,ID_ONE, (LPARAM)MAKELONG(FALSE, 0));

it will disable the button in both the cases ,including the icon is not showing also, where icon image should be grey out.

Secondly if user click second toolbar button, I am calling the code such as :-

GetToolBarCtrl().SetState(ID_TWO,TBSTATE_PRESSED); //  where ID_TWO is the id of second button

as per above function the button should be in pressed state, but in my case its not changing the state of that button either.

1

1 Answers

0
votes

Usually you don't modify the toolbar buttons directly like that with MFC. Instead, you should add an onUpdate command message handler for the menu command id that is used by the toolbar button. In that handler, you can e.g. Call Enable() and SetCheck() on the pCmdUI object that you get as a parameter.

Here is a starting point in the MS documentation for you:

https://docs.microsoft.com/en-us/cpp/mfc/on-update-command-ui-macro?view=vs-2019