Re: How to push a button in a toolbar programmatically?
Thx all for answare, the solution for me should be to call the
SetCheck() in the OnInitDialog and set the first button on the toolbar
checked but I can't find the right way to do this. Can you take a look
at my code please? I created the toolbar in this way:
BOOL CSetupMgrDlg::OnInitDialog()
{
......
......
// Toolbar Left
if (!m_leftToolbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE
| CBRS_LEFT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC)
|| !m_leftToolbar.LoadToolBar(IDR_LEFTTOOLBAR))
{
TRACE0(_T("Failed to create toolbar\n"));
return -1; // fail to create
}
m_leftToolbar.SetBarStyle(m_leftToolbar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_leftToolbar.SetToolBarInfoForCustomization();
m_leftToolbar.RestoreState();
m_leftToolbar.MarkDefaultState();
curPos = GetCurrentPosition( LEFTTABBAR);
m_leftToolbar.SetWindowPos( &CWnd::wndNoTopMost, curPos.left,
curPos.top, curPos.Width(), curPos.Height(), SWP_SHOWWINDOW);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
m_leftToolbar.ShowWindow( SW_SHOW);
InitToolBar( LEFTBAR);
........
.......
}
void CSetupMgrDlg::InitToolBar( int whatBar)
{
switch( whatBar)
{
....................
....................
case LEFTBAR:
{
int index;
UINT style;
index = 0;
while( m_leftToolbar.GetItemID(index) != ID_PLACEHOLDER40) index++;
style = m_leftToolbar.GetButtonStyle( index);
style |= BTNS_CHECKGROUP;
m_leftToolbar.SetButtonStyle( index, style);
index = 0;
while( m_leftToolbar.GetItemID(index) != ID_PLACEHOLDER41) index++;
style = m_leftToolbar.GetButtonStyle( index);
style |= BTNS_CHECKGROUP;
m_leftToolbar.SetButtonStyle( index, style);
}
break;
...................
...................
}
}
How can I get the control of a button on the m_leftToolbar? I tryed
some ways with not success.
Thanks
paolob