Implementing Docking control Bar in Child Frame | CodeGuru

Implementing Docking control Bar in Child Frame

In a multiple view application, sometimes I need to implement different control bars for different views. This article presents how to implement docking control bar in a child frame. Suppose we want to embed a tool bar and a status bar in a child frame. First, declare them in ChildFrm.h: protected: // control bar embedded […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 14, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

In a multiple view application, sometimes I need to implement different control bars for different views. This article presents how to implement docking control bar in a child frame.
Suppose we want to embed a tool bar and a status bar in a child frame. First, declare them in ChildFrm.h:

protected:  // control bar embedded members
	...
	CStatusBar m_wndStatusBar;
	CToolBar m_wndToolBar;
	static UINT indicators[4]; // indicators of status bar


Next, over write CChildFrame::OnCreate(). Create control bars just as we do in CmainFrame.

int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO: Add your specialized creation code here
	if (!m_wndToolBar.Create(this) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1; // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1; // fail to create
	}

	// TODO: Remove this if you don't want tool tips or a resizeable toolbar
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	// TODO: Delete these three lines if you don't want the toolbar to be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
	return 0;
}

Then write the array of status bar’ indicators as following:

UINT CChildFrame::indicators[4] =
{
	ID_SEPARATOR, // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

Now you can build the project and play with it. However, the menu item “Tool Bar” does not work properly at this stage. When there is any child frame in the main frame, the menu effects the tool bar in the child frame only. You can’t toggle the show/hide of the tool bar in the main frame until you close all the child frames. Now I am going to create 2 new menu terms, Main Frame Tool Bar, and Child Frame Tool Bar, to toggle show/hide of the 2 tool bars. Use ClassWizard to add following 2 member functions in CMainFrame.

void CMainFrame::OnViewMainframetoolbar()
{
	// TODO: Add your command handler code here
	if(m_wndToolBar.IsWindowVisible())
		m_wndToolBar.ShowWindow(SW_HIDE);
	else
		m_wndToolBar.ShowWindow(SW_SHOW);
	this->SendMessage(WM_SIZE, 0, 0);
}

void CMainFrame::OnUpdateViewMainframetoolbar(CCmdUI* pCmdUI)
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_wndToolBar.IsWindowVisible());
}

Similarly add following member functions in CChildFrame.

void CChildFrame::OnViewChildframetoolbar()
{
	// TODO: Add your command handler code here
	if(m_wndToolBar.IsWindowVisible())
		m_wndToolBar.ShowWindow(SW_HIDE);
	else
		m_wndToolBar.ShowWindow(SW_SHOW);
	this->SendMessage(WM_SIZE, 0, 0);
}

void CChildFrame::OnUpdateViewChildframetoolbar(CCmdUI* pCmdUI)
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_wndToolBar.IsWindowVisible());
}

Build the project and see how the menu items work.

The same technique works for ReBar. If you have any qestion, feel free to drop me a line.


Download demo project – 23KB

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.