How To Add a Toolbar in an MDI Child WindowID: Q155141
|
By default, an AppWizard-generated MDI application has a toolbar in its
main application window (CMDIFrameWnd-derived class). This toolbar is
shared by all the MDI child windows (CMDIChildWnd-derived class) in the
application. In some cases, it would be useful to have a toolbar appear in
each MDI child window. This is demonstrated in the following sample code.
Because CMDIChildWnd is a CFrameWnd-derived class, the toolbar in an MDI
child window may be dockable. This can be easily achieved by calling such
functions as EnableDocking() and DockControlBar().
class CChildFrame : public CMDIChildWnd
{
...
CToolBar m_wndToolBar;
}
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Create a toolbar window. IDR_CHILDFRAME is the resource name
// of the toolbar to be loaded.
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_CHILDFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
// TODO: Remove this if you don't want tool tips or a
// resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// TODO: Delete these three lines if you don't want the toolbar
// to be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
For information on using ClassWizard, please refer to VC++ Books Online.
Additional query words: 4.00 4.10 4.20 kbdse
Keywords : kbMFC KbUIDesign kbVC
Version : 4.00 4.10 4.20
Platform : NT WINDOWS
Issue type :
Last Reviewed: August 3, 1999