MFC Document Application CToolBar: Set two toolbars and dock to the same side to go

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.