Implementing Docking control Bar in Child Frame

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

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



Comments

  • How to draw the toolbar background?

    Posted by Legacy on 10/10/2003 12:00am

    Originally posted by: zzfa

    I found that your menubar'color differ from toolbar's,Can you tell me how to draw the toolbar background where is no button?
    thank you very much!

    Reply
  • docking toolbar in Windows SDK??

    Posted by Legacy on 05/05/2001 12:00am

    Originally posted by: Shibu J

    How do I add a docking toolbar with images on each button in Windows Platform SDK?

    Reply
  • Toolbar in a view?

    Posted by Legacy on 07/17/1999 12:00am

    Originally posted by: Tesic Goran

    Hi,
    
    

    How can I add toolbar in a CView derived class?

    Thank you beforehand

    Best regards

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

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

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