Docking Toolbars Side-By-Side

.
If you are interested in more articles written by Kirk Stowell, you can click here to visit his home page.

There are several 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.

Download demo project - (29 KB)

Last updated December 21, 1998



Comments

  • Docking side by side in the mdi child?

    Posted by rioch on 06/22/2009 11:01am

    I cannot get this to work for the mdichild frame. Is it possible to get the toolbars side by side there as well?

    Reply
  • Docking toolbars in more than one row

    Posted by Laurs on 06/10/2005 08:48am

    It looks that MFC has problems when you try to drag toolbars to posaition them after each other, when there is more than one row. Has anybody a solution?

    Reply
  • http://www.bcgsoft.com

    Posted by Legacy on 08/29/2003 12:00am

    Originally posted by: The Best GUI Tools - VS.NET and Office XP/2003 Look!

    http://www.bcgsoft.com

    Reply
  • Wonderful!

    Posted by Legacy on 07/18/2003 12:00am

    Originally posted by: HS

    Just what I was looking for!!

    Reply
  • Thanks A Lot

    Posted by Legacy on 06/29/2003 12:00am

    Originally posted by: Snakebyte

    I spent more than an hour looking for some toolbar property/method which could do the same In MSDN

    This is exactly what I wanted to do.
    Thanks a lot

    Reply
  • TreeCtrl intoa a dockable Toolbar?

    Posted by Legacy on 02/11/2003 12:00am

    Originally posted by: Manuel

    How can I get into a ToolBar (dockable and resizable) a TreeCtrl

    Reply
  • How to dock a toolbar at right side?

    Posted by Legacy on 12/23/2002 12:00am

    Originally posted by: xianbin zheng

    When create a toolbar and dock at top or bottom, it will align at left defaultly. But what can I do to dock it align right.

    Reply
  • How about three and more toolbars???

    Posted by Legacy on 06/05/2002 12:00am

    Originally posted by: writeus

    While I add three toolbars,It's work wrong!!

    How can I do???

    Help!!!

    Reply
  • Perfect ! ! !

    Posted by Legacy on 04/24/2002 12:00am

    Originally posted by: Johnn J

    Just what i was looking for!

    Reply
  • That seems be good !

    Posted by Legacy on 03/28/2002 12:00am

    Originally posted by: BBBKOM

    You are so creative!

    Reply
  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 11, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT One of the languages that have always been supported with the Intel® RealSense™ SDK (Software Developer Kit) is JavaScript, specifically so that web-enabled apps could be created. Come hear from Intel Expert Bob Duffy as he reviews his own little "space shooting" game where the orientation of your face controls the aiming reticle to help teach developers how to write apps and games in JavaScript that can use facial and gesture …

  • Live Event Date: May 6, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT Where are you in your plans to adopt Disaster Recovery-as-a-Service? Are you just getting started? Fighting an uphill battle with management? At Cisco, Zerto and iland, we've seen it all – from the early adopters who excitedly rushed to implement DRaaS with us nine years ago to the IT folks dragging their business leaders into the future. With our years of experience, we've learned there are six types of DRaaS leaders – but which type …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date