Click here to Skip to main content
Licence 
First Posted 15 Dec 1999
Views 180,207
Bookmarked 53 times

Docking Toolbars Side-By-Side

By | 15 Dec 1999 | Article
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

    About the Author

    Kirk Stowell

    CEO
    Codejock Software
    United States United States

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    GeneralMy vote of 5 PinmemberRobert Kisel11:33 13 Mar '11  
    GeneralThanks Pinmemberbusch2923:03 29 Aug '09  
    GeneralShow a button in pressed state using CMFCToolbar PinmemberFarhat Aisha23:43 24 Sep '08  
    QuestionHow to put Toolbar at customized position Pinmemberakira3223:58 22 Sep '08  
    GeneralThe same with CMFCMenuBar Pinmemberbharath jois2:35 21 Aug '08  
    GeneralThat's what i want PinmemberXiong Shijie6:17 19 Sep '07  
    GeneralRe: That's what i want PinmemberThornets1:36 5 Aug '08  
    QuestionHi(I want to dock ToolBar To its original position ) [modified] Pinmembertupi_kasvala1:27 8 Sep '07  
    QuestionHow to remove the empty space in front of toolbar2 if uncheck view->toolbar Pinmemberjd0113:20 20 Nov '06  
    GeneralBeautiful Pinmembernadiric16:04 31 Aug '06  
    GeneralToolBar 1 not displayed properly PinmemberAbhi Lahare20:18 22 May '06  
    QuestionHow to control the position of the docking toolbar if the main frame window is resized? PinmemberMary Gao13:49 12 Apr '05  
    AnswerRe: How to control the position of the docking toolbar if the main frame window is resized? Pinmembermark-w16:48 20 Dec '05  
    GeneralRe: How to control the position of the docking toolbar if the main frame window is resized? Pinmemberjd018:20 22 Nov '06  
    GeneralOdd Artifacts PinmemberBob Ciora5:52 30 Jan '05  
    GeneralThanks! PinmemberBob Ciora9:49 28 Jan '05  
    I came across this problem a while ago, and was already on a new project before I had a chance to figure it out. I've bookmarked this article in case I have to do this again Smile | :)

     
    Bob Ciora
    GeneralClasses Derived from CToolBar PinsussNoahNNFN7:59 11 Jan '05  
    GeneralRe: Classes Derived from CToolBar Pinmembericaro10:33 14 Jun '06  
    Generalremoving border/seperator Pinmembersocall019:26 13 Dec '04  
    GeneralRe: removing border/seperator PinmemberLars [Large] Werner3:41 17 Mar '05  
    GeneralRe: removing border/seperator PinsussAnonymous18:59 12 Jul '05  
    GeneralThanks alot! Pinmemberipichet1:27 19 Oct '04  
    GeneralDisplaying the Toolbar 2 PinmemberAudalio_Jr7:14 12 May '04  
    GeneralRe: Displaying the Toolbar 2 PinmemberDave_B22:41 24 Aug '04  
    GeneralRe: Displaying the Toolbar 2 PinmemberKJ Dugan4:05 21 Nov '04  

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

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

    Permalink | Advertise | Privacy | Mobile
    Web01 | 2.5.120528.1 | Last Updated 16 Dec 1999
    Article Copyright 1999 by Kirk Stowell
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid