Professional UI Solutions
Site Map   /  Register


Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » DockControlBar with CExtToolControlBar objects. Collapse All
Subject Author Date
Dave Foster Sep 15, 2009 - 8:43 PM

CMainWnd::DockControlBar( m_ToolBar, AFX_IDW_DOCKBAR_LEFT, &rect ) appears to undesirably resize our m_ToolBar when docked.  This did not occur when running with an MFC CToolBar.  m_ToolBar is an instance of CExtToolControlBar which was constructed with a 6 or so buttons (implemented from a bitmap), two CExtComboBox items and two CStatic objects inserted dynamically (they were "created", then "positioned" on the m_ToolBar).  I have read that one should use CExtToolControlBar::DockControlBar() instead of CMainWnd::DockControlBar(), but I cannot see the equivelent functionality in the CExtControlBar class.



Technical Support Sep 17, 2009 - 3:35 AM

The CExtToolControlBar::_CalcSize() method does not assume all buttons have a equal size. Yes, it invokes the CSize sizeDefButton = _GetDefButtonSize(); code at startup to retrieve the default size of tool bar button. But the sizeDefButton object is just required for computing the real size of each button. The default size is assumed to be minimal. The CExtToolControlBar::_CalcSize() method is really organized as the for loop through all the toolbar buttons. This loop really computes size of each button:

       CSize sizeTBB(
                        (!bVerticallyDocked) || m_bPaletteMode
It would be really interesting to take a look at the overridden method in your project. It would be really interesting to find out what’s the real source of the problem?

Dave Foster Sep 17, 2009 - 1:36 PM

The solution required supplying functions normally supplied by CToolBar, and overriding the _CalcSize() function in CExtToolControlBar:

void CMyToolBar::SetSizes( SIZE sizeButton, SIZE sizeImage )


     m_SizeButton = sizeButton;

     m_SizeImage = sizeImage;

     int nButtonCount = CExtToolControlBar::GetButtonsCount();

     int nOffset = 0;

     for ( int i = 0; i < nButtonCount; i++ ) {   

          int nButtonWidth = GetButtonID( i ) != ID_SEPARATOR ? : 8;

          CRect ClientRect( nOffset, 0, nOffset + nButtonWidth, ); // l, t, r, b

          CExtToolControlBar::GetButton( i )->SetRect( ClientRect );

          nOffset += nButtonWidth;



void CMyToolBar::SetButtonInfo( int nIndex, UINT nID, UINT nStyle, int iImage )


     CExtToolControlBar::SetButtonInfo( nIndex, nID, nStyle );

     int nOffset = 0;

     for ( int i = 0; i < nIndex; i++ ) { 

          CRect Rect;

          GetButtonRect( i, Rect );

          nOffset += Rect.Width();


     CRect ClientRect( nOffset, 0, nOffset + iImage, ); // l, t, r, b

     CExtToolControlBar::GetButton( nIndex )->SetRect( ClientRect );


void CMyToolBar::GetItemRect( int nIndex, LPRECT lpRect )


     CExtToolControlBar::GetButtonRect( nIndex, lpRect );


CSize CMyToolBar::_CalcSize( BOOL bVerticallyDocked )


#if 0

     CSize BarSize = CExtToolControlBar::_CalcSize( bVerticallyDocked );


     CSize BarSize( bVerticallyDocked ? : 0, bVerticallyDocked ? 0 : );

     int nButtonCount = CExtToolControlBar::GetButtonsCount();

     for ( int i = 0; i < nButtonCount; i++ ) {

          CRect ItemRect;

          GetItemRect( i, &ItemRect );

          if ( bVerticallyDocked )

      += ItemRect.Height();


      += ItemRect.Width(); 



     return BarSize;


The button width of "8" for a separator is a WAG.

Technical Support Sep 17, 2009 - 3:03 AM

The CExtControlBar::Dock***() methods should be used with CExtControlBar resizable control bars. The CFrameWnd::DockControlBar() method should be used with CExtToolControlBar , CExtMenuControlBar, CExtPanelControlBar panel bars and other fixed size bars which cannot be resized by the user when docked.

The problem is to do with something else. Please drop an e-mail to the support mail box at this web site and attach the source code of your classes mentioned in your forum message and the source code of the main frame class.

Dave Foster Sep 16, 2009 - 2:02 PM

I found the solution to my own problem.  I found that not only did DocControlBar() have the problem, but so did FloatControlBar().  After much wading through source code (both Prof-UIS and MFC), I discovered that CExtToolControlBar::_CalcSize() actually assumes that all buttons are the same width/height.  For the particular contol bar in question, this not the case.  I over-rode the function _CalcSize() and now have the result that we expect.