Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - How to dynamically add a control to a toolbar?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to dynamically add a control to a toolbar?

 Post Reply Post Reply
Author
Message
yluo9 View Drop Down
Newbie
Newbie


Joined: 07 May 2009
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote yluo9 Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
yluo9 View Drop Down
Newbie
Newbie


Joined: 07 May 2009
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote yluo9 Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
yluo9 View Drop Down
Newbie
Newbie


Joined: 07 May 2009
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote yluo9 Quote  Post ReplyReply Direct Link To This Post Posted: 19 May 2010 at 11:37pm
Many thanks!
CalcDockingLayout is really acting.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.