Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

DOCKTOOL Sample: Demonstrates Dockable Toolbars

The DOCKTOOL sample demonstrates support for dockable toolbars. A dockable toolbar can be attached, or docked, to any side of its parent window, or it can be detached, or floated, in its own miniframe window using CMiniFrameWnd.

Building and Running the Sample

To build and run the DOCKTOOL sample

  1. Open the solution docktool.sln.
  2. On the Build menu, click Build.
  3. On the Debug menu, click Start Without Debugging.

Supporting Dockable Toolbars

The following three steps are necessary to place a dockable toolbar in your application:

  1. Enable docking for the frame window or destination using the CFrameWnd::EnableDocking function. One DWORD parameter indicates which side of the frame window accepts docking. To dock control bars anywhere, pass CBRS_ALIGN_ANY to EnableDocking.
  2. Enable docking for the toolbar or source by calling CControlBar::EnableDocking for each toolbar. Specify the destination sides to which the toolbar should dock. If none of the sides specified match the sides enabled for docking in the frame window, the toolbar cannot dock; it will float. Once it has been floated, it remains a floating toolbar, unable to dock to the frame window.
  3. Dock the toolbar to the frame window by calling CFrameWnd::DockControlBar. Conversely, call CFrameWnd::FloatControlBar to detach a dockable toolbar from the frame window.

If you do not complete all three steps, your application will display a standard toolbar. The last two steps must be performed for each dockable toolbar in your application.

To retain the state of dockable toolbars (whether docked or floating) between invocations of your application, use the CControlBar::SetBarStyle and CControlBar::GetBarStyle functions to retrieve and restore the settings of any particular control bar. Normally, this information is stored in the application's .ini file using CFrameWnd::SaveBarState and retrieved using CFrameWnd::LoadBarState.


This sample demonstrates the following keywords:

AfxGetApp; CArchive::IsStoring; CComboBox::Create; CComboBox::DeleteString; CComboBox::GetCount; CComboBox::InsertString; CComboBox::SetCurSel; CControlBar::GetBarStyle; CControlBar::SetBarStyle; CDialog::DoModal; CDocument::OnNewDocument; CFrameWnd::Create; CFrameWnd::DockControlBar; CFrameWnd::EnableDocking; CFrameWnd::LoadBarState; CFrameWnd::RecalcLayout; CFrameWnd::SaveBarState; CMenu::GetSubMenu; CMenu::LoadMenu; CMenu::TrackPopupMenu; CObject::AssertValid; CObject::Dump; CObject::Serialize; CRect::OffsetRect; CString::IsEmpty; CToolBar::Create; CToolBar::GetItemRect; CToolBar::LoadBitmap; CToolBar::SetButtonInfo; CToolBar::SetButtons; CView::GetDocument; CView::OnDraw; CWinApp::AddDocTemplate; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::OnFileNew; CWnd::ClientToScreen; CWnd::DoDataExchange; CWnd::FromHandlePermanent; CWnd::GetParentFrame; CWnd::GetStyle; CWnd::GetWindowPlacement; CWnd::GetWindowRect; CWnd::GetWindowText; CWnd::Invalidate; CWnd::IsZoomed; CWnd::OnClose; CWnd::OnCreate; CWnd::PreTranslateMessage; CWnd::SendMessage; CWnd::SetWindowPlacement; CWnd::SetWindowPos; CWnd::SetWindowText; CWnd::ShowWindow; GetProfileInt; GetProfileString; GetStockObject; HIWORD; LOWORD; LoadBitmap; WriteProfileString; wsprintf

Note   Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

MFC Samples

© 2015 Microsoft