Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use CToolBarCtrl to check a button in the toolbar

Status
Not open for further replies.

olin

Technical User
Jun 6, 2003
67
US
I want to check a button in the toolbar, whose button's style is TBBS_CHECKBOX alrealy. I wrote:

m_wndToolBar.SetButtonStyle(0, TBSTYLE_CHECK);
CToolBarCtrl& Ctrl = m_wndToolBar.GetToolBarCtrl();
Ctrl.CheckButton(0);

but it didn't work! However, if I changed CheckButton with some other functions such as DeleteButton, it did work. Why is only the CheckButton unavailable?

Thanks!
 
The first parameter in the CheckButton() function should be the id of the button and the second could be true or false.
The prototype of the CheckButton() is :
BOOL CheckButton(int nID, bool bCheck = true)
The call you are doing :
CheckButton(0);
is equivalent to :
CheckButton(0,true); which means the button with the command ID = 0 and I think this doesn't exist.
So the right code to cehck a button with the index idx is:
TBBUTTON lptbutton;
int idx = 0;
m_wndToolBar.SetButtonStyle(idx, TBSTYLE_CHECK);
CToolBarCtrl& Ctrl = m_wndToolBar.GetToolBarCtrl();
BOOL bGet = Ctrl.GetButton(idx,&lptbutton);
Ctrl.CheckButton(lptbutton.idCommand,true);

-obislavu-
 
Thanks, I got it.

I made a stupid mistake. I thought the parameter of CheckButton was index of the buttons.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top