Print Page | Close Window

How to dynamically add a control to a toolbar?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=16714
Printed Date: 27 February 2025 at 2:14am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to dynamically add a control to a toolbar?
Posted By: yluo9
Subject: How to dynamically add a control to a toolbar?
Date 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




Replies:
Posted By: yluo9
Date Posted: 18 May 2010 at 9:41pm
Originally posted by yluo9 yluo9 wrote:

...

But it doesn't work.
...



"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.


Posted By: jimmy
Date 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



Posted By: yluo9
Date Posted: 19 May 2010 at 11:37pm
Many thanks!
CalcDockingLayout is really acting.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net