Click here to Skip to main content
11,926,429 members (58,295 online)
Click here to Skip to main content
Add your own
alternative version


62 bookmarked

Simple splitter with CWnd-derived panes

, 18 Apr 2004
Rate this:
Please Sign up or sign in to vote.
A splitter window class, which combines the basic CSplitterWnd functionality and professional look with the ability to use CWnd-derived panes.


Yes, it's yet another splitter window class. So why I release a new class, when there are a plenty of similar classes? The answer is simple. All splitter window classes at CodeProject can be IMHO divided into two parts:

  • These derived from original MFC CSplitterWnd. They look nice and give a lot of advantages to classical CSplitterWnd, but deriving from CSplitterWnd restrict you to use only CView-derived windows in it.
  • The others, which I can use in various windows - but when I compiled and tested them, they didn't look as pretty as the CSplitterWnd.

In this article I offer a class, which is not derived from CSplitterWnd. It allows you to use simple CWnd-derived windows. But it's combined with professional looking of the original CSplitterWnd. Some routines I took from MFC source code. Please be forbearing while reading this article. It's my first article at CodeProject Smile | :) .


My goal in CSimpleSplitterWnd design was to simulate the basic features of CSplitterWnd. With this class you can make several panes arranged either horizontally or vertically. It doesn't offer automatic splitting, shared scroll bars and intersection trackers. I didn't find it very useful - but if there are enough people, who did, I can add some of these features Smile | :) The idea of CSimpleSplitter (compared to CSplitterWnd) is that pane windows are independent to each other, hence they are also responsible for their scrolling and borders.

Using the code

The layout of splitter is set in constructor:

CSimpleSplitter(int nPanes, UINT nOrientation = SSP_HORZ,   
 int nMinSize = 30, int nBarThickness = 3);

nPanes is number of the panes, nOrientation should be either SSP_HORZ or SSP_VERT. nMinSize is the minimal height (or width) of any pane - it is important in recalculating layout algorithm, when you resize the splitter. nBarThickness is height or width of bars between panes. All of these properties remain fixed during lifetime of the splitter instance. The creation of splitter and its panes is straightforward:

BOOL Create(CWnd* pParent, UINT nID = AFX_IDW_PANE_FIRST);
BOOL CreatePane(int nIndex, CWnd* pPaneWnd, DWORD dwStyle,   
 DWORD dwExStyle, LPCTSTR lpszClassName = NULL);

Panes are indexed from 0 to nPanes - 1. The parameters dwStyle , dwExStyle and lpszClassName are passed to pPaneWnd->CreateEx() (If you want to bind a created window with a pane, use SetPane instead). You can specify for example the borders of panes there. In demo app, the "large" panes have a WS_EX_CLIENTEDGE extended style, while the three "flat" panes have WS_EX_STATICEDGE extended style. The splitter bar alone is only a gray rectangle, so if you don't specify any edge and set the gray background to pane windows, you can use the splitter in dialogs too.

The following five methods are analogous to CSplitterWnd methods, so they don't require a special documentation.

int GetPaneCount() const;void SetPane(int nIndex, CWnd* pPaneWnd);
CWnd* GetPane(int nIndex) const;
virtual void SetActivePane(int nIndex);
CWnd* GetActivePane(int* pIndex) const;

However, setting the pane widths or heights uses different technique:

void SetPaneSizes(const int* sizes);

You pass an array of nPanes integers. They specify relative sizes of panes. You can use any scale, the panes are resized proportionally to the sum of the array members. When you resize the whole splitter, the sizes of panes are changed proportionally to their actual sizes. If necessary, they're adjusted to m_nMinSize.

void GetPaneRect(int nIndex, CRect& rcPane) const;
void GetBarRect(int nIndex, CRect& rcBar) const;

With these functions you can retrieve the position of panes in splitter client coordinates. Bars are indexed from 1 to nPanes - 1.

And that's all. Look at the SimpleSplitterApp demo, especially the CMainFrame::OnCreate code, you will know everything!

Points of Interest

When I programmed the splitter, I was confused, how the framework redraws resized window. If you resize the top or left border, the framework first only move the window content in corresponding direction, and then it calls OnPaint(). So the window was redrawn twice and in the splitter this looked ugly.

Fortunately, there is a message handler CWnd::OnWindowPosChanging. You can avoid the initial moving of content, if you see SWP_NOCOPYBITS as you see in CSimpleSplitter and CChildWnd code. I think that this is useful in many other cases that splitters.


  • 11. 2. 2004 - First version released
  • 24. 3. 2004 - Some bugs fixed (see the messages below). In the SetPaneSizes function now you should pass only relative sizes, not absolute.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Robert A. T. Káldy
Web Developer
Czech Republic Czech Republic
Nowadays, I'm studying Econometrics and Software Systems at Charles University in Prague. Parallel to it, I work as a Windows developer in a railway interlocking company.
I consider myself as a C++ fundamentalist, simply because I haven't ever found any better language. If you know about any, please drop me a mail (and we can dispute about it Smile | :) )
Some friends say that I'm workoholic and I answer, yes, of course and what is wrong?
You can visit my homepage, but it's completely in Czech Smile | :)

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
JunfengGuo14-Jul-15 15:51
memberJunfengGuo14-Jul-15 15:51 
GeneralRe: My vote of 5 Pin
JunfengGuo14-Jul-15 16:22
memberJunfengGuo14-Jul-15 16:22 
GeneralRe: My vote of 5 Pin
JunfengGuo14-Jul-15 16:52
memberJunfengGuo14-Jul-15 16:52 
QuestionThanks Pin
Jonnie White1-Jun-15 1:04
memberJonnie White1-Jun-15 1:04 
GeneralMy vote of 5 Pin
Jonnie White1-Jun-15 1:03
memberJonnie White1-Jun-15 1:03 
QuestionHow would I install a dialog bar within a given SimpleSplitter pane? Pin
Michael B Pliam23-Oct-12 13:13
memberMichael B Pliam23-Oct-12 13:13 
QuestionOnly 3 stars for me Pin
llothar29-Jan-12 17:03
memberllothar29-Jan-12 17:03 
QuestionMDI Child window with CFormView panes are not re-sized Pin
Shashidhar Kamath8-Dec-11 12:16
memberShashidhar Kamath8-Dec-11 12:16 
QuestionHow to add CDialog based object as one of the pane Pin
Shashidhar Kamath7-Dec-11 10:46
memberShashidhar Kamath7-Dec-11 10:46 
Questionhow to use the simple splitter with CWnd-derived panes Pin
errieman13-Jul-11 22:22
membererrieman13-Jul-11 22:22 
GeneralGetBarRect fix Pin
ChrisJohnShort19-Dec-06 13:25
memberChrisJohnShort19-Dec-06 13:25 
GeneralCListView Pin
Devil for ever5-Jun-06 11:17
memberDevil for ever5-Jun-06 11:17 
QuestionDoKeyboardSplit() Pin
Ortwin Basselmann2-Mar-06 23:29
memberOrtwin Basselmann2-Mar-06 23:29 
QuestionHow to create a splitter inside CWnd derived class object? Pin
Paul, Snehasish2-Feb-06 21:06
memberPaul, Snehasish2-Feb-06 21:06 
GeneralSetting pane with arbitray parent Pin
Diarrhio26-Jul-05 21:18
memberDiarrhio26-Jul-05 21:18 
GeneralAdding Dialog Controls directly Pin
xrestassuredx22-Apr-05 12:02
memberxrestassuredx22-Apr-05 12:02 
GeneralRe: Adding Dialog Controls directly Pin
Robert A. T. Káldy11-May-05 7:04
memberRobert A. T. Káldy11-May-05 7:04 
GeneralRe: Adding Dialog Controls directly [modified] Pin
Member 458205418-Apr-08 6:16
memberMember 458205418-Apr-08 6:16 
GeneralResizing when parent resizes Pin
Andrew Phillips27-Jan-05 20:54
memberAndrew Phillips27-Jan-05 20:54 
GeneralNeed help with splitter Pin
pank00721-Oct-04 14:53
memberpank00721-Oct-04 14:53 
GeneralRe: Need help with splitter Pin
Robert A. T. Káldy24-Oct-04 11:15
memberRobert A. T. Káldy24-Oct-04 11:15 
QuestionDoes SetPane only use in windows whose parent is SplitWindow ? Pin
RealityC10-Oct-04 18:21
memberRealityC10-Oct-04 18:21 
AnswerRe: Does SetPane only use in windows whose parent is SplitWindow ? Pin
Robert A. T. Káldy11-Oct-04 12:29
memberRobert A. T. Káldy11-Oct-04 12:29 
AnswerRe: Does SetPane only use in windows whose parent is SplitWindow ? Pin
Andrew Phillips27-Jan-05 21:01
memberAndrew Phillips27-Jan-05 21:01 
GeneralRe: Does SetPane only use in windows whose parent is SplitWindow ? Pin
Anonymous1-Feb-05 7:16
sussAnonymous1-Feb-05 7:16 
GeneralHiding panes Pin
defenestrator22-Sep-04 6:02
sussdefenestrator22-Sep-04 6:02 
GeneralRe: Hiding panes Pin
Robert A. T. Káldy23-Sep-04 4:29
memberRobert A. T. Káldy23-Sep-04 4:29 
GeneralRe: My dialog does not display properly inside a splitter Pin
Robert A. T. Káldy9-Sep-04 8:22
memberRobert A. T. Káldy9-Sep-04 8:22 
GeneralMy dialog does not display properly inside a splitter Pin
Frodenor9-Sep-04 3:42
sussFrodenor9-Sep-04 3:42 
GeneralRe: My dialog does not display properly inside a splitter Pin
Robert A. T. Káldy9-Sep-04 8:22
memberRobert A. T. Káldy9-Sep-04 8:22 
GeneralRe: My dialog does not display properly inside a splitter Pin
Shawn Liu21-Sep-05 21:48
memberShawn Liu21-Sep-05 21:48 
GeneralUsing this inside a CSizingControlBar and two controls Pin
DonGuitar14-Jun-04 3:24
memberDonGuitar14-Jun-04 3:24 
GeneralRe: Using this inside a CSizingControlBar and two controls Pin
Robert A. T. Káldy15-Jun-04 8:27
memberRobert A. T. Káldy15-Jun-04 8:27 
GeneralAdd Label Title the views Pin
YongSei3-May-04 13:01
memberYongSei3-May-04 13:01 
GeneralRe: Add Label Title the views Pin
Robert A. T. Káldy4-May-04 1:06
memberRobert A. T. Káldy4-May-04 1:06 
GeneralRe: Add Label Title the views Pin
YongSei4-May-04 8:16
memberYongSei4-May-04 8:16 
GeneralRe: Add Label Title the views Pin
Robert A. T. Káldy4-May-04 23:18
memberRobert A. T. Káldy4-May-04 23:18 
GeneralRe: Add Label Title the views Pin
YongSei5-May-04 6:20
memberYongSei5-May-04 6:20 
QuestionLicense? Pin
Robert F19-Apr-04 23:52
sussRobert F19-Apr-04 23:52 
AnswerRe: License? Pin
Robert A. T. Káldy20-Apr-04 0:06
memberRobert A. T. Káldy20-Apr-04 0:06 
GeneralRe: License? Pin
Robert F20-Apr-04 3:30
sussRobert F20-Apr-04 3:30 
GeneralIt's exactly what I'm looking for Pin
xufeisjtu7-Mar-04 5:57
memberxufeisjtu7-Mar-04 5:57 
GeneralnBarTickness Pin
Kochise25-Feb-04 0:29
memberKochise25-Feb-04 0:29 
GeneralPosition of bars Pin
Kochise25-Feb-04 0:55
memberKochise25-Feb-04 0:55 
GeneralRe: Position of bars Pin
Robert A. T. Káldy20-Apr-04 9:35
memberRobert A. T. Káldy20-Apr-04 9:35 
GeneralRe: nBarTickness Pin
Robert A. T. Káldy25-Mar-04 12:30
memberRobert A. T. Káldy25-Mar-04 12:30 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 19 Apr 2004
Article Copyright 2004 by Robert A. T. Káldy
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid