DOCKTOOL: Demonstrates Dockable Toolbars

Click to open or copy the DOCKTOOL project files.

DOCKTOOL demonstrates dockable toolbar support. 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 mini-frame window using CMiniFrameWnd. 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::Enable3dControls; 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