![]() |
How to dynamically add a control to a toolbar? |
Post Reply
|
| Author | |
yluo9
Newbie
Joined: 07 May 2009 Status: Offline Points: 4 |
Post Options
Thanks(0)
Quote Reply
Topic: How to dynamically add a control to a toolbar?Posted: 17 May 2010 at 10:27pm |
|
Hi, please see code blew:
BOOL CMyDialog::OnInitDialog() { ... CXTPToolBar *pToolBar = GetToolBar(PA_IDR_TB_GS); if ( pToolBar ) { CXTPControls *pControls = pToolBar->GetControls(); CString strLevel; for ( int nLevel = nLevelNum - 1; nLevel >= 0; --nLevel ) { strLevel.Format( _T("%d"), nLevel ); pControls->Add( xtpControlButton, PA_IDC_PAGE_BTN0 + nLevel, strLevel, 1 ); } } ... } But it doesn't work. Can anybody tell me why and how? Thanks |
|
![]() |
|
yluo9
Newbie
Joined: 07 May 2009 Status: Offline Points: 4 |
Post Options
Thanks(0)
Quote Reply
Posted: 18 May 2010 at 9:41pm |
"it doesn't work" means that the dynamically added buttons don't show, but if I call pControls->GetCount() or pControls->GetVisibleCount(), its' return value includes the dynamically added buttons number. |
|
![]() |
|
jimmy
Senior Member
Joined: 11 November 2003 Location: Austria Status: Offline Points: 516 |
Post Options
Thanks(0)
Quote Reply
Posted: 19 May 2010 at 2:19pm |
|
Hi,
i use this. and call CreateButtons() after add buttons. void CXTPDynamicToolbar::UpdateCalc() { CRect rcClient; GetParent()->GetClientRect(rcClient); CSize sz = CalcDockingLayout(rcClient.Width(), /*LM_HIDEWRAP|*/ LM_HORZDOCK | LM_HORZ | LM_COMMIT); MoveWindow(rcClient.left, rcClient.top, rcClient.Width(), sz.cy); Invalidate(FALSE); } void CXTPDynamicToolbar::CreateButtons() { UpdateCalc(); m_pControls->CreateOriginalControls(); } Jimmy |
|
![]() |
|
yluo9
Newbie
Joined: 07 May 2009 Status: Offline Points: 4 |
Post Options
Thanks(0)
Quote Reply
Posted: 19 May 2010 at 11:37pm |
|
Many thanks!
CalcDockingLayout is really acting. |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |