Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / MFC
Article

Docking Toolbars Side-By-Side

Rate me:
Please Sign up or sign in to vote.
4.90/5 (37 votes)
15 Dec 1999 254K   3.2K   59   40
Demonstrates how to dock toolbars side-by-side
  • Download demo project - 29 Kb
  • Sample Image - toolbar_docking.gif

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

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    CEO Codejock Technologies, LLC
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
    This is a Organisation (No members)


    Comments and Discussions

     
    QuestionHidden Toolbars? Pin
    Andornot16-Feb-18 7:58
    Andornot16-Feb-18 7:58 
    QuestionThanks Pin
    rbrunton31-Jan-16 4:51
    rbrunton31-Jan-16 4:51 
    GeneralMy vote of 5 Pin
    Robert Kisel13-Mar-11 11:33
    Robert Kisel13-Mar-11 11:33 
    GeneralRe: My vote of 5 Pin
    Albert Holguin3-Oct-13 11:08
    professionalAlbert Holguin3-Oct-13 11:08 
    GeneralThanks Pin
    busch2929-Aug-09 23:03
    busch2929-Aug-09 23:03 
    GeneralShow a button in pressed state using CMFCToolbar Pin
    Farhat Aisha24-Sep-08 23:43
    Farhat Aisha24-Sep-08 23:43 
    QuestionHow to put Toolbar at customized position Pin
    akira3222-Sep-08 23:58
    akira3222-Sep-08 23:58 
    GeneralThe same with CMFCMenuBar Pin
    bharath jois21-Aug-08 2:35
    bharath jois21-Aug-08 2:35 
    GeneralThat's what i want Pin
    Xiong Shijie19-Sep-07 6:17
    Xiong Shijie19-Sep-07 6:17 
    GeneralRe: That's what i want Pin
    Thornets5-Aug-08 1:36
    Thornets5-Aug-08 1:36 
    QuestionHi(I want to dock ToolBar To its original position ) [modified] Pin
    tupi_kasvala8-Sep-07 1:27
    tupi_kasvala8-Sep-07 1:27 
    QuestionHow to remove the empty space in front of toolbar2 if uncheck view->toolbar Pin
    jd0120-Nov-06 13:20
    jd0120-Nov-06 13:20 
    GeneralBeautiful Pin
    nadiric31-Aug-06 16:04
    nadiric31-Aug-06 16:04 
    GeneralToolBar 1 not displayed properly Pin
    Abhi Lahare22-May-06 20:18
    Abhi Lahare22-May-06 20:18 
    QuestionHow to control the position of the docking toolbar if the main frame window is resized? Pin
    Mary Gao12-Apr-05 13:49
    Mary Gao12-Apr-05 13:49 
    AnswerRe: How to control the position of the docking toolbar if the main frame window is resized? Pin
    mark-w20-Dec-05 16:48
    mark-w20-Dec-05 16:48 
    GeneralRe: How to control the position of the docking toolbar if the main frame window is resized? Pin
    jd0122-Nov-06 8:20
    jd0122-Nov-06 8:20 
    GeneralOdd Artifacts Pin
    Bob Ciora30-Jan-05 5:52
    Bob Ciora30-Jan-05 5:52 
    GeneralThanks! Pin
    Bob Ciora28-Jan-05 9:49
    Bob Ciora28-Jan-05 9:49 
    GeneralClasses Derived from CToolBar Pin
    NoahNNFN11-Jan-05 7:59
    sussNoahNNFN11-Jan-05 7:59 
    GeneralRe: Classes Derived from CToolBar Pin
    icaro14-Jun-06 10:33
    icaro14-Jun-06 10:33 
    Generalremoving border/seperator Pin
    socall0113-Dec-04 9:26
    socall0113-Dec-04 9:26 
    GeneralRe: removing border/seperator Pin
    Lars [Large] Werner17-Mar-05 3:41
    professionalLars [Large] Werner17-Mar-05 3:41 
    GeneralRe: removing border/seperator Pin
    Anonymous12-Jul-05 18:59
    Anonymous12-Jul-05 18:59 
    GeneralRe: removing border/seperator Pin
    Albert Holguin3-Oct-13 11:06
    professionalAlbert Holguin3-Oct-13 11:06 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.