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 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

IT Offers

Comments

  • The activities the competition has been doing in the matter of nike and the things that you want to complete totally different.

    Posted by icoppyapedcap on 04/21/2013 09:26pm

    Ky [url=http://hunter-rain-boots.webnode.jp]レインブーツハンター[/url] eVt [url=http://hunterrainbootsjp.webnode.jp]レインブーツメンズ[/url] u VnyYpf ZqzA [url=http://hunter-boots8.webnode.jp]レインブーツハンター[/url] bt W [url=http://rain-boots-men.webnode.jp]ハンター長靴[/url] lz [url=http://hunter-rain-boots-ja.webnode.jp]レインブーツ人気[/url] NxoUzpTbq Y[url=http://rainshoesja.webnode.jp]ブーツ[/url] jiNqtJokDv [url=http://ja-hunter-rain-boots.webnode.jp]レインブーツハンター[/url] c QprDsr [url=http://rain-boots-popular.webnode.jp]レインブーツメンズ[/url] Njt [url=http://rain-boots-men6.webnode.jp]ハンターレインブーツ[/url] Yyf Sbk [url=http://jahunterrainboots.webnode.jp]ハンターブーツ[/url] Zit

    Reply
  • 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.

Go Deeper

  • The penetration of virtual servers is approaching 50 percent in IT infrastructures, yet administrators are only backing up, on average, 68 …
  • This buyers guide provides independent research and test results to help you determine your endpoint protection requirements and identify …
  • When the economy is stable, a company's IT organization may view Finance as just one of many internal customers competing for attention. But …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds