5,691,626 members and growing! (13,146 online)
Email Password   helpLost your password?
Desktop Development » Toolbars & Docking windows » Toolbars     Intermediate

Docking Toolbars Side-By-Side

By Kirk Stowell

Demonstrates how to dock toolbars side-by-side
VC6, C++Windows, NT4, MFC, VS6, Visual Studio, Dev

Posted: 15 Dec 1999
Updated: 15 Dec 1999
Views: 128,610
Bookmarked: 38 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
58 votes for this Article.
Popularity: 7.99 Rating: 4.53 out of 5
2 votes, 6.1%
1
0 votes, 0.0%
2
1 vote, 3.0%
3
3 votes, 9.1%
4
27 votes, 81.8%
5
  • 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



    Occupation: Web Developer
    Location: United States United States

    Other popular Toolbars & Docking windows articles:

    Article Top
    Sign Up to vote for this article
    You must Sign In to use this message board.
    FAQ FAQ Noise ToleranceSearch Search Messages 
     Layout  Per page   
     Msgs 1 to 25 of 33 (Total in Forum: 33) (Refresh)FirstPrevNext
    GeneralShow a button in pressed state using CMFCToolbarmemberFarhat Aisha0:43 25 Sep '08  
    QuestionHow to put Toolbar at customized positionmemberakira320:58 23 Sep '08  
    GeneralThe same with CMFCMenuBarmemberbharath jois3:35 21 Aug '08  
    GeneralThat's what i wantmemberXiong Shijie7:17 19 Sep '07  
    GeneralRe: That's what i wantmemberThornets2:36 5 Aug '08  
    QuestionHi(I want to dock ToolBar To its original position ) [modified]membertupi_kasvala2:27 8 Sep '07  
    GeneralHow to remove the empty space in front of toolbar2 if uncheck view->toolbarmemberjd0114:20 20 Nov '06  
    GeneralBeautifulmembernadiric17:04 31 Aug '06  
    GeneralToolBar 1 not displayed properlymemberAbhi Lahare21:18 22 May '06  
    GeneralHow to control the position of the docking toolbar if the main frame window is resized?memberMary Gao14:49 12 Apr '05  
    GeneralRe: How to control the position of the docking toolbar if the main frame window is resized?membermark-w17:48 20 Dec '05  
    GeneralRe: How to control the position of the docking toolbar if the main frame window is resized?memberjd019:20 22 Nov '06  
    GeneralOdd ArtifactsmemberBob Ciora6:52 30 Jan '05  
    GeneralThanks!memberBob Ciora10:49 28 Jan '05  
    GeneralClasses Derived from CToolBarsussNoahNNFN8:59 11 Jan '05  
    GeneralRe: Classes Derived from CToolBarmembericaro11:33 14 Jun '06  
    Generalremoving border/seperatormembersocall0110:26 13 Dec '04  
    GeneralRe: removing border/seperatormemberLars [Large] Werner4:41 17 Mar '05  
    GeneralRe: removing border/seperatorsussAnonymous19:59 12 Jul '05  
    GeneralThanks alot!memberipichet2:27 19 Oct '04  
    GeneralDisplaying the Toolbar 2memberAudalio_Jr8:14 12 May '04  
    GeneralRe: Displaying the Toolbar 2memberDave_B23:41 24 Aug '04  
    GeneralRe: Displaying the Toolbar 2memberKJ Dugan5:05 21 Nov '04  
    Generalsimple and easy, thanks!memberJohn Wong11:57 9 Sep '02  
    GeneralHow to Docking More than Three Toolbars Side-By-Side??memberAnonymous20:02 5 Jun '02  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 15 Dec 1999
    Editor: Chris Maunder
    Copyright 1999 by Kirk Stowell
    Everything else Copyright © CodeProject, 1999-2008
    Web20 | Advertise on the Code Project