Transferred from: http://blog.csdn.net/panshiqu/article/details/9369891#
Dock multiple toolbars at one side of a window at the same time. For this kind of docking method, using the above-mentioned tool bar control function DockControlBar lprect parameter, through the Control tool bar docking Rectangle Area method can realize
1: Add the following member function definitions in MainFrm.h
// Increase Public : void Dockcontrolbarleftof (ctoolbar* Bar, ctoolbar* leftof);
2: Implementing member functions in MainFrm.cpp
void CMainFrame::D ockcontrolbarleftof (ctoolbar* bar, ctoolbar* leftof) { //Set toolbar to dock to the same edge CRect rect; DWORD DW; UINT n=0; RecalcLayout (); Re -Display leftof->getwindowrect (rect); Rect. Offsetrect (1, 0); Dw=leftof->getbarstyle (); N= (dw&cbrs_align_top)? Afx_idw_dockbar_top:n; N= (dw&cbrs_align_bottom&&n==0)? afx_idw_dockbar_bottom:n; N= (dw&cbrs_align_left&&n==0)? Afx_idw_dockbar_left:n; N= (dw&cbrs_align_right&&n==0)? Afx_idw_dockbar_right:n; DockControlBar (Bar,n,&rect); }
In this function, you should be aware of the call to the RecalcLayout () function and the Offsetrect () function, the previous function is used to re-display the adjusted client area and the toolbar, and the latter function to re-determine the rectangular area, This is equivalent to dragging the Second toolbar window onto the previous toolbar and releasing it using the mouse.
3: Just call the above function, if you create a new toolbar variable is M_wndtoolbarnav, then use the following program to replace the original MainFrm.cpp in the fragment
Original:
TODO: If you don't need a dockable toolbar, delete the three rows of m_wndtoolbar.enabledocking (cbrs_align_any); EnableDocking (cbrs_align_any); DockControlBar (&m_wndtoolbar);
after replacement:
TODO: If you don't need a dockable toolbar, delete the three rows of m_wndtoolbar.enabledocking (cbrs_align_any); M_wndtoolbarnav.enabledocking (cbrs_align_any); EnableDocking (cbrs_align_any); DockControlBar (&m_wndtoolbar); Dockcontrolbarleftof (&m_wndtoolbarnav,&m_wndtoolbar);//mainly here
After the three steps above, you can see the effect.
MFC Document Application CToolBar: Set two toolbars and dock to the same side to go