Click here to Skip to main content
13,903,757 members
Click here to Skip to main content
Add your own
alternative version


311 bookmarked
Posted 12 Jul 2010
Licenced CPOL


, 12 Jul 2010
Rate this:
Please Sign up or sign in to vote.
A control that allows you to create multiple areas with tabs that you can pull with the mouse and as a result change the configuration of these areas.

Sample Image


This control is based on the CWnd class and can be placed as a child window anywhere, for example, in the client area of a frame or dialog. The control allows you to create hierarchically nested areas, each of which may have tabs. Using the mouse, the user has the ability to move tabs with them and related child windows. This allows the user to customize the location and size of working areas to their liking. One possible use of MultiPaneCtrl is as a window filling the client area of the frame. The result is a simple, easily configurable interface.

Using the code

Each pane can be in one of two states:

  1. Be empty (do not have child panes and tabs) or have tabs.
  2. Have child panes (to be a line).

The current state is determined by the function IsLine. Many functions can be called for panes in only one of two states.

The basic rules for working with the control are:

  1. Root pane is created when you create a control and you can not delete it.
  2. In all operations, instead of a handle of the root pane (GetRoot), you can use NULL.
  3. Adding tabs and converting to a line can only be done for panes that don’t have child panes.
  4. When you convert a pane to a line, create a child pane, and it passes all the tabs to the convertible pane.
  5. When you delete a pane, its tabs pass to the parent pane, provided that this pane doesn’t have child panes and it is the only child of its parent pane.

Here is an example of the algorithm for creating the MultiPaneCtrl (fill panes and tabs):

  1. Initial state.
  2. Sample Image

  3. Adding tabs to the root pane (MultiPaneCtrl::AddTab).
  4. Sample Image

  5. Conversion of the root pane to a line (MultiPaneCtrl::ConvertToLine).
  6. Sample Image

  7. Adding a child pane to the root pane (MultiPaneCtrl::Add).
  8. Sample Image

  9. Conversion of Pane2 to a line (MultiPaneCtrl::ConvertToLine).
  10. Sample Image

  11. Adding a child pane to Pane2 (MultiPaneCtrl::Add).
  12. Sample Image

  13. Adding tabs to Pane3 and Pane4 (MultiPaneCtrl::AddTab).
  14. Sample Image

Removing panes from the MultiPaneCtrl. Example 1:

  1. Initial state.
  2. Sample Image

  3. Removing Pane3.
  4. Sample Image

  5. Removing Pane2.
  6. Sample Image

Remove panes from MultiPaneCtrl. Example 2:

  1. Initial state.
  2. Sample Image

  3. Removing Pane2.
  4. Sample Image

For each pane which doesn’t have child panes, by default, a TabCtrl control is created. It is described in my previous article, located at All TabCtrl controls are created as child windows for MultiPaneCtrl and do not form additional levels of nesting. This is especially important because modern versions of Windows have a limited number of nesting windows in each other, which often does not exceed 13-15. The function GetTabCtrl allows you to get a pointer to TabCtrl. It can be called only for a pane which is not a line. You can use this pointer for a particular tabbed pane or call methods of the MultiPaneCtrl class. For example, to add a tab to a pane, use the function MultiPaneCtrl::AddTab.

To create the control and add elements to it, you can do the following steps:

MultiPaneCtrlEx < MultiPaneCtrlStyle_VS2003_client > m_MultiPaneCtrl;
CTreeCtrl m_Tree1, m_Tree2;
CEdit m_Edit1;
CListCtrl m_List1, m_List2;


// Creation and initialization of child windows.
   TVS_HASLINES,CRect(0,0,0,0),this,300)==0 ||
   TVS_HASLINES,CRect(0,0,0,0),this,301)==0 ||
   m_Edit1.Create(WS_CHILD | ES_MULTILINE,CRect(0,0,0,0),this,302)==0 ||
   m_List1.Create(WS_CHILD | LVS_REPORT,CRect(0,0,0,0),this,303)==0 ||
   m_List2.Create(WS_CHILD | LVS_REPORT,CRect(0,0,0,0),this,304)==0)
    return -1;

m_Tree1.InsertItem(_T("CTreeCtrl 1"));
m_Tree2.InsertItem(_T("CTreeCtrl 2"));
m_Edit1.SetWindowText(_T("CEdit 1"));
m_List1.InsertColumn(0,_T("CListCtrl 1"),LVCFMT_LEFT,100);
m_List1.InsertItem(0,_T("Item 1"));
m_List2.InsertColumn(0,_T("CListCtrl 2"),LVCFMT_LEFT,100);
m_List2.InsertItem(0,_T("Item 1"));

// Creation of MultiPaneCtrl object.
if(m_MultiPaneCtrl.Create(this,WS_CHILD | WS_VISIBLE, 
   CRect(0,0,400,300),100/*id of MultiPaneCtrl*/)==false)
    return -1;

CImageList imagelist,imagelistDis, imagelistSys;
CBitmap bmp,bmpDis, bmpSys;

imagelist.Create(16,16,ILC_COLOR24 | ILC_MASK,7,0);

imagelistDis.Create(16,16,ILC_COLOR24 | ILC_MASK,7,0);

imagelistSys.Create(14,14,ILC_COLOR24 | ILC_MASK,7,0);




// Loading state or creation default state.
    MultiPaneCtrl::Tabs tabs;

        // create default state.
        HPANE h1 = m_MultiPaneCtrl.ConvertToLine(NULL,false);

        HPANE h2 = m_MultiPaneCtrl.Add(NULL);

        HPANE h3 = m_MultiPaneCtrl.ConvertToLine(h2,true);

        HPANE h4 = m_MultiPaneCtrl.Add(h2);
        HPANE h5 = m_MultiPaneCtrl.ConvertToLine(h4,false);
        HPANE h6 = m_MultiPaneCtrl.Add(h4);

catch(std::bad_alloc &)
{    return -1;


The control doesn’t perform any drawing, and for this, it calls methods of the interface MultiPaneCtrlDraw. Also, for determining the thickness of the border and splitters, it uses an interface IMultiPaneCtrlRecalc. User operations are defined by methods of the interface MultiPaneCtrlUserAbility. These include the ability to insert the pane in a certain area when you drag it with the mouse, as well as showing system buttons (close, menu, scroll). In general, for proper working of the control, it needs to set the style. To do this, you must implement the functions of the IMultiPaneCtrlStyle interface and pass a pointer to it using the method InstallStyle. Besides pointers to the above interfaces, you must return a pointer to the interface ITabCtrlStyle (see article about TabCtrl). This will be used to define the appearance and behavior of all tabs in the control. An object of the class of the style must exist during the working of the control. To do this, you can create an intermediate class like MultiPaneCtrlComplex. If you are working with only one style, then use the template class MultiPaneCtrlEx. The class name of the style is defined as a template parameter, for example:

MultiPaneCtrlEx < MultiPaneCtrlStyle_VS2003_client > m_MultiPaneCtrl;

Some styles have already been created. For example, styles similar to the docking/floating panels in Visual Studio 2003, 2008, and 2010. To create your own styles, see the classes MultiPaneCtrlStyle_VS2003_client, MultiPaneCtrlStyle_VS2008_client_classic etc. The class MultiPaneCtrlRecalcStub creates a default implementation for the functions of the IMultiPaneCtrlRecalc interface. You can use it to create your own style objects.

In the process of pulling tabs with the mouse for better visualization, we ca use docking markers. They appear on the panes, and when you hover on them, they show the position of the future insertion of the pulling tab. To use it, you need to call SetDockMarkers. One of the parameters of this function is an object for defining graphic resources and their location to create the appearance of the marker. Three objects have been created and used in the demo of this article. They are MarkersLayoutA, MarkersLayoutB, and MarkersLayoutC to set markers look similar to the markers used in VS2008, VS2005, and VS2010, respectively. To construct your own markers, use these classes as examples, also see information in the DockingMarkers.h file.

The control does not send messages to the parent window and uses an interface MultiPaneCtrlNotify for the notification of the events. Use SetNotifyManager to set the pointer to your implementation of MultiPaneCtrlNotify.

The control requires a call to Update after you add or delete tabs, as well as change its properties and state.

The loading state of the control is based on the content of the object MultiPaneCtrl::Tabs. It must keep information about tabs in the Registry or another archive, for use when loading. You can load information from the working control (MultiPaneCtrl::SaveTabs) or add tabs manually (MultiPaneCtrl::Tabs::Add).

By default, all drawing is based on double buffering, it excludes any blinking. If you want, use VirtualWindow::DoubleBuffering(false) to disable double buffering.

Good luck.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Borodenko Oleg
Software Developer JSC 'Phazotron-7'
Belarus Belarus
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionUndocking Panes... Pin
FebruaryGuy2621-Oct-14 17:35
memberFebruaryGuy2621-Oct-14 17:35 
AnswerRe: Undocking Panes... Pin
Borodenko Oleg21-Oct-14 20:29
memberBorodenko Oleg21-Oct-14 20:29 
GeneralI am very appreciate of your work, fantastic job Pin
motoHello17-Mar-14 22:36
membermotoHello17-Mar-14 22:36 
Questionhow to response the message OnTabRButtonDown Pin
fangdanwei13-Feb-14 3:36
memberfangdanwei13-Feb-14 3:36 
AnswerRe: how to response the message OnTabRButtonDown Pin
Borodenko Oleg13-Feb-14 4:08
memberBorodenko Oleg13-Feb-14 4:08 
GeneralRe: how to response the message OnTabRButtonDown Pin
fangdanwei15-Feb-14 2:54
memberfangdanwei15-Feb-14 2:54 
GeneralRe: how to response the message OnTabRButtonDown Pin
Borodenko Oleg15-Feb-14 3:06
memberBorodenko Oleg15-Feb-14 3:06 
GeneralRe: how to response the message OnTabRButtonDown Pin
fangdanwei15-Feb-14 3:17
memberfangdanwei15-Feb-14 3:17 
GeneralRe: how to response the message OnTabRButtonDown Pin
Borodenko Oleg15-Feb-14 3:27
memberBorodenko Oleg15-Feb-14 3:27 
GeneralThanks a lot. Pin
fangdanwei15-Feb-14 3:34
memberfangdanwei15-Feb-14 3:34 
Questionhere is a bug; Pin
Sam.Liang26-Aug-13 4:22
memberSam.Liang26-Aug-13 4:22 
AnswerRe: here is a bug; Pin
Borodenko Oleg27-Aug-13 0:08
memberBorodenko Oleg27-Aug-13 0:08 
GeneralRe: here is a bug; Pin
Sam.Liang27-Aug-13 2:45
memberSam.Liang27-Aug-13 2:45 
Questionhow about hide/re-show panel or tab ? Pin
skyformat99@gmail.com19-Jun-13 18:45
memberskyformat99@gmail.com19-Jun-13 18:45 
AnswerRe: how about hide/re-show panel or tab ? Pin
Sergej8911-Jul-13 3:23
memberSergej8911-Jul-13 3:23 
GeneralRe: how about hide/re-show panel or tab ? Pin
skyformat99@gmail.com14-Jul-13 22:23
memberskyformat99@gmail.com14-Jul-13 22:23 
GeneralRe: how about hide/re-show panel or tab ? Pin
Borodenko Oleg14-Jul-13 23:34
memberBorodenko Oleg14-Jul-13 23:34 
GeneralRe: how about hide/re-show panel or tab ? Pin
skyformat99@gmail.com15-Jul-13 14:50
memberskyformat99@gmail.com15-Jul-13 14:50 
GeneralRe: how about hide/re-show panel or tab ? Pin
Borodenko Oleg16-Jul-13 3:47
memberBorodenko Oleg16-Jul-13 3:47 
Questionhow about update window? Pin
FansHill16-Feb-13 23:06
memberFansHill16-Feb-13 23:06 
AnswerRe: how about update window? Pin
Borodenko Oleg16-Feb-13 23:46
memberBorodenko Oleg16-Feb-13 23:46 
GeneralRe: how about update window? Pin
FansHill17-Feb-13 4:09
memberFansHill17-Feb-13 4:09 
GeneralMy vote of 5 Pin
skyformat99@gmail.com13-Nov-12 3:57
memberskyformat99@gmail.com13-Nov-12 3:57 
GeneralMy vote of 5 Pin
Ali Khanlarkhani20-Oct-12 21:12
memberAli Khanlarkhani20-Oct-12 21:12 
Questioncan't download Pin
kunpengnet24-Sep-12 16:20
memberkunpengnet24-Sep-12 16:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190306.1 | Last Updated 12 Jul 2010
Article Copyright 2010 by Borodenko Oleg
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid