Share via


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 provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

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.

Keywords

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

Other Resources

MFC Samples