Click here to Skip to main content
Licence CPOL
First Posted 24 Dec 2008
Views 22,066
Downloads 2,908
Bookmarked 55 times

SplitterCtrl (flexible control with custom drawing)

By | 24 Dec 2008 | Article
It is similar to CSplitterWnd, but it is easier to use and with lots of possibilities.

Introduction

This control is necessary for the partition of the dialog, main or child window of your program by several parts. You can appropriate to each part the window, which SplitterCtrl will manage. As a result we will get a matrix with the controls. The SplitterCtrl is derived from CWnd and is a common control based on MFC. Generally, SplitterCtrl is similar to CSplitterWnd, but it is easier to use. For example, you can create a complex matrix. For this into one or several cells it is necessary to put the same SplitterCtrl and also to divide on parts.

The control can use scaling sizes of cells with changes in its sizes. In this case the binding of a matrix to one of four angles of the parental window is possible. Also, you can use a mouse for the dynamic or static pulling of boundaries between the windows and much more.

Using the Code

The control includes four classes:

Class Description

SplitterCtrlBase

Base class. Includes all the base functionality, but it does not draw itself.

SplitterCtrl

Derived from SplitterCtrlBase. Also it is derived from ISplitterCtrlRecalc and SplitterCtrlDraw classes for the correction of sizes of parts and to draw the control respectively.

ISplitterCtrlRecalc

This class makes it possible to assign sizes of parts of the control. For using be inherited from ISplitterCtrlRecalc and realize its functions. Also in constructor of your class it is necessary to call the SetRecalcManager function with pointer of ISplitterCtrlRecalc object.

SplitterCtrlDraw

This class makes it possible to draw the control. You can draw your window yourself. For this be inherited from SplitterCtrlDraw and realize its functions. Also in constructor of your class it is necessary to call the SetDrawManager function with pointer of SplitterCtrlDraw object.

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

   #include "SplitterCtrl.h"

   SplitterCtrl m_Splitter;
   CListCtrl m_List1, m_List2;
      …
      …
   if(m_Splitter.Create(this,
      WS_CHILD | WS_VISIBLE,CRect(0,0,200,200),
      ID_SplitterCtrl)==false)
      return -1;   // error.

   // Create child controls.
   if(m_List1.Create(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | LVS_REPORT,CRect(0,0,0,0),
      &m_Splitter,ID_List1)==0 ||
      m_List2.Create(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | LVS_REPORT,CRect(0,0,0,0),
      &m_Splitter,ID_List2)==0)
      return -1;   // error.
   m_List1.InsertColumn(0,"00",LVCFMT_LEFT,100);
   m_List2.InsertColumn(0,"01",LVCFMT_LEFT,100);

   // Add child items in the m_Splitter.
   m_Splitter.AddRow();
   m_Splitter.AddColumn();
   m_Splitter.AddColumn();
   m_Splitter.SetWindow(0,0,m_List1.m_hWnd);
   m_Splitter.SetWindow(0,1,m_List2.m_hWnd);

   // Load state from registry.
   if(m_Splitter.LoadState(AfxGetApp(),"SplitterCtrl","SplitterState")==false)
   {   m_Splitter.Update();
       m_Splitter.SetEqualWidthColumns();   // error - create default state.
   }
   m_Splitter.Update();

You can manage the control as a normal matrix, dynamically insert and delete rows and columns (AddRow/AddColumn, InsertRow/InsertColumn, DeleteRow/DeleteColumn). The control makes it possible to assign the sizes (SetWidthForStatic/SetHeightForStatic, SetWidthForDynamic/SetHeightForDynamic), and also to equalize widths and heights of the cells (SetEqualWidthColumns/SetEqualHeightRows). The control is expected to call the Update function to show the results that are set by functions InsertRow, DeleteColumn, SetHeightForStatic, SetWidthsForDynamic, etc.

The control is able to save and load its state from the registry or other sources (LoadState/SaveState). This is one of the possibilities. To get the full power, look at the opened interface of the SplitterCtrlBase and SplitterCtrl classes.

Good luck :-)

License

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

Belarus Belarus

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 PinmemberMember 44082418:36 8 Dec '10  
GeneralReally Fantastic Control PinmemberMember 45424459:56 2 Jul '09  
GeneralThanks PinmemberMember 460503410:01 3 Feb '09  
GeneralHi Oleg, PinmemberKeith Vinson10:20 30 Dec '08  
GeneralLooks interesting - But why this versus normal CSplitterWnd Pinmemberc-sharp5:11 24 Dec '08  
GeneralRe: Looks interesting - But why this versus normal CSplitterWnd PinmemberBorodenko Oleg9:59 24 Dec '08  
GeneralRe: Looks interesting - But why this versus normal CSplitterWnd PinmemberAndreone13:58 29 Dec '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.5.120517.1 | Last Updated 24 Dec 2008
Article Copyright 2008 by Borodenko Oleg
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid