Toll Free: (877) 723-1442 U.S. and Canada
Support
ActiveX / COM
Visual C++ / MFC
Customer Spotlight
Corporate Partners
Contact Sales

Call center available M-F 9:00 - 6:00 US Eastern Time.

U.S. and Canada
(877) 723-1442

International
(517) 625-5729

Email

Docking Toolbars Side-By-Side

Author: Kirk Stowell
Posted: November 16, 2004
Environment: Visual C++ MFC

Downloads:
  article06_prj.zip - Source Files with Demo Project [28.3 KB]

There are many articles about docking toolbars.  However, I felt that this was important enough to mention here.  The same information can be found at Microsoft's MSDN site.  Here it is in a nutshell...

Add the following method to your CMainFrame class:

 void CMainFrame::DockControlBarLeftOf(

                         CToolBar* Bar, CToolBar* LeftOf)

 {

     CRect rect;

     DWORD dw;

     UINT n;

 

     // get MFC to adjust the dimensions of all docked ToolBars

     // so that GetWindowRect will be accurate

     RecalcLayout(TRUE);

 

     LeftOf->GetWindowRect(&rect);

     rect.OffsetRect(1,0);

     dw=LeftOf->GetBarStyle();

     n = 0;

     n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;

     n = (dw&CBRS_ALIGN_BOTTOM && n==0) ?

                                 AFX_IDW_DOCKBAR_BOTTOM : n;

     n = (dw&CBRS_ALIGN_LEFT && n==0) ?

                                 AFX_IDW_DOCKBAR_LEFT : n;

     n = (dw&CBRS_ALIGN_RIGHT && n==0) ?

                                 AFX_IDW_DOCKBAR_RIGHT : n;

 

     // When we take the default parameters on rect, DockControlBar

     // will dock each Toolbar on a seperate line. By calculating a

     // rectangle, we are simulating a Toolbar being dragged to that

     // location and docked.

     DockControlBar(Bar,n,&rect);

 }

Now, in your CMainFrame::OnCreate, instead of using DockControlBar, use DockControlBarLeftOf:

 m_wndToolBar1.EnableDocking(CBRS_ALIGN_ANY);

 m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY);

 EnableDocking(CBRS_ALIGN_ANY);

 DockControlBar(&m_wndToolBar1);

 DockControlBarLeftOf(&m_wndToolBar2,&m_wndToolBar1);

This will dock m_wndToolBar2 left of m_wndToolBar1.



Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Other products and/or company names may be trademarks or registered trademarks of their respective owners.