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.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

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.

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


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.

Other Resources