CTRLBARS: Illustrates Custom Control Bars

Click to open or copy the CTRLBARS project files.

The CTRLBARS sample illustrates a wide variety of customization options for control bars:

Running CTRLBARS

When you first run CTRLBARS, all the various controls are visible.

The View menu lets you hide or unhide (show) any of the first four of the above controls bars. The dialog bar is always visible. The hide/show state of the Tools, Styles, and Palette control bars is immediately reflected in the Hide/Show check boxes in the dialog bar. You can also hide or show one of the other control bars by toggling its check box.

With the Dlg Bar Top command on the View menu, you can rearrange the control bars so that the dialog bar is at the top of the Z-order of the control bars. When the dialog bar is at the top, it extends along the entire left border of the window except for the menu and title bars. The left ends of the two toolbars touch the dialog bar. When the dialog bar is returned to its original Z-order position (after all of the other control bars), the top of the dialog bar touches the lower edge of the second toolbar bar, and the bottom of the dialog bar touches the upper edge of the status bar. This reflects the basic algorithm that control bars are allocated window real estate on a first-come, first-serve basis.

The Style menu lets you select one of the four text alignment styles — Left, Centered, Right, or Justified. Any selection you make is immediately reflected in the Style Bar's  combo box and in the corresponding button. Similarly, you can make a selection either by choosing one of the styles in the Style Bar combo box or by pressing one of the four buttons. The new selection is immediately reflected in the states of the other controls and in the Style menu.

The Palette menu lets you change the tool arrangement of the palette from 3-by-4 to 2-by-6.

When you select a tool from the Palette, the status bar message line shows "You have selected the <type> tool," in which <type> indicates which of the 12 tools you selected. This selection is reflected in the combo box in the dialog bar. You can also select a tool using this combo box.

The status bar, in addition to showing the most recently selected tool, also shows the status of three keys — ins, CAPS LOCK, and NUM LOCK.

This sample demonstrates the following keywords:

AfxFormatString1; AfxGetApp; AfxIsValidAddress; AfxRegisterWndClass; AfxThrowResourceException; BitBlt; CBrush::CreateSolidBrush; CCmdUI::ContinueRouting; CCmdUI::Enable; CCmdUI::SetCheck; CCmdUI::SetText; CComboBox::AddString; CComboBox::Create; CComboBox::GetCurSel; CComboBox::GetLBText; CComboBox::SetCurSel; CControlBar::GetBarStyle; CControlBar::SetBarStyle; CDC::Attach; CDC::Detach; CDC::PatBlt; CDC::RectVisible; CDialogBar::Create; CDumpContext::GetDepth; CFont::CreateFontIndirect; CFrameWnd::LoadFrame; CFrameWnd::RecalcLayout; CFrameWnd::SetMessageText; CGdiObject::Attach; CObject::AssertValid; CObject::Dump; CRect::Height; CRect::InflateRect; CRect::SetRectEmpty; CRect::Width; CStatusBar::Create; CStatusBar::GetPaneInfo; CStatusBar::SetIndicators; CStatusBar::SetPaneInfo; CString::LoadString; CToolBar::CToolBar; CToolBar::CommandToIndex; CToolBar::Create; CToolBar::GetButtonInfo; CToolBar::GetItemID; CToolBar::GetItemRect; CToolBar::LoadBitmap; CToolBar::SetButtonInfo; CToolBar::SetButtons; CToolBar::SetHeight; CToolBar::SetSizes; CWinApp::Enable3dControls; CWinApp::InitInstance; CWinApp::OnIdle; CWnd::ClientToScreen; CWnd::CreateEx; CWnd::GetCapture; CWnd::GetClientRect; CWnd::GetDC; CWnd::GetDlgItem; CWnd::GetOwner; CWnd::GetParentFrame; CWnd::GetSafeHwnd; CWnd::GetStyle; CWnd::GetWindowRect; CWnd::Invalidate; CWnd::InvalidateRect; CWnd::OnCancelMode; CWnd::OnCreate; CWnd::OnLButtonDown; CWnd::OnLButtonUp; CWnd::OnMouseActivate; CWnd::OnMouseMove; CWnd::OnSysColorChange; CWnd::PreCreateWindow; CWnd::ReleaseDC; CWnd::SendMessage; CWnd::SetCapture; CWnd::SetFont; CWnd::SetWindowPos; CWnd::ShowWindow; CWnd::UpdateDialogControls; CWnd::UpdateWindow; CreateBitmap; CreateCompatibleBitmap; CreateCompatibleDC; CreateDIBitmap; CreatePatternBrush; CreatePen; CreateSolidBrush; DeleteDC; DeleteObject; FillRect; FindResource; FrameRect; FreeResource; GetActiveWindow; GetBValue; GetCapture; GetDC; GetDeviceCaps; GetGValue; GetNextWindow; GetObjectType; GetParent; GetRValue; GetStockObject; GetSysColor; GetSystemMetrics; GetVersion; GetWindow; HIBYTE; InvertRect; LOBYTE; LoadCursor; LoadIcon; LoadResource; LockResource; MAKEINTRESOURCE; OffsetRect; PatBlt; RGB; ReleaseCapture; ReleaseDC; SelectObject; SendMessage; SetActiveWindow; SetBkColor; SetCapture; SetROP2; SetRect; SetTextColor; StretchDIBits; UpdateWindow; free; lstrcpy; malloc; memcpy; memset