Simple Splitter


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


I have seen many programmers asking how to create a splitter window in a dialog box. Unfortunately MFC does not provide a splitter control that can be directly embedded into a dialog box. CSplitterWnd is somehow designed to be used only inside a frame window. I have also seen a few attempts, but none is generic and easy to use.

The class I am presenting is designed for general purpose. The name is CSplitterBar, the function is to provide a splitter bar that can be embedded into any kind of windows, such as a frame, a view or a dialog box.

The example I am giving here is to create a CSplitterbar control in a dialog box. If you would like to use CSplitterBar in other kinds of windows, the procedure described here can be easily adapted.

  1. Firstly, declare an object of CSplitterBar in your dialog class:

CSplitterBar m_wndSplitterBar;

2. Secondly, create the m_wndSplitterBar object in the InitDialog function:


//Create a splitter bar

CRect rect(0,0,0,0);

m_wndSplitterBar.Create(WS_CHILD|WS_BORDER|WS_DLGFRAME|WS_VISIBLE, rect,this,999);


3. Finally, setup the windows on the left pane and right pane of the splitter bar:

//Insert the splitter bar between a tree and a list control



That is all your need to do, and let the CSplitterBar handle all of the rest. The full source code can be downloaded from here:

To use CSplitterBar in your own project, you only need to include two files: SplitterBar.h and SplitterBar.cpp.


There is also a message "WM_SPLITTER_MOVED" is generated by the splitter bar whenever the control is dragged then dropped. If you want to do something special when the splitter is repositioned, then provide a message handler for this message.

Download Documentation and Source simple_splitter.zip (48.5k)


  • Right drag fix

    Posted by christig on 12/26/2004 07:05am

    void CSplitterBar::OnLButtonUp(UINT nFlags, CPoint point) ... else { ... if(point.x < pointLeftMost.x) point.x=pointLeftMost.x; if(point.x > pointRightMost.x) point.x=pointRightMost.x-m_rectSplitter.Width();//fix

  • Saying thanks then another big question.

    Posted by Legacy on 02/17/2004 08:00am

    Originally posted by: Kimjuhoon

    This is exactly what i wanted to find out. thanks so much for posting this class. but I have one more big difficult problem.

    Originally, I was supposed to put some buttons on / under the splitterbar. but I really don't know how to make it.

    good example is MSN messanger that is conversation dialog.

    There's some buttons under splitter bar such as smiley and fond setting and so on.

  • Can it be used in an ATL composite control?

    Posted by Legacy on 10/10/2003 07:00am

    Originally posted by: Joar Vatnaland

    I have an ATL view class based on CComCompositeControl. Is it possible to use the splitterbar there? I haven't been able to make it work.

  • Invisible Splitter Bars Please!

    Posted by Legacy on 02/28/2003 08:00am

    Originally posted by: Jimmy


    Is there any way to create fully functional splitter bars that are invisible?

    Basically everything is great, BUT I don't want the splitter bars to display. Not setting WS_VISIBLE makes the control invisible, but also disables any use of the control.


  • Cursor disappered when using staticly linked MFC

    Posted by Legacy on 11/12/2002 08:00am

    Originally posted by: Hacker

    So you must add cursor resource to your project by hand when using staticly linked MFC. Or any other resolutions I don't know?

  • dragger drawn outside pane

    Posted by Legacy on 10/17/2002 07:00am

    Originally posted by: Christian Utama

    A little fix to prevent the dragger to be drawn outside its client panes:

    // add this function

    BOOL CSplitterBar::isInside(CPoint pt)
    CRect left, right, total;
    total = left | right;
    CPoint temp = pt;
    if (total.PtInRect(temp))
    return TRUE;
    return FALSE;

    void CSplitterBar::DrawDraggingBar(CPoint point,DRAGFLAG df)

    // add this line
    if (!isInside(point)) return;

  • Overlapping Splitter Bars

    Posted by Legacy on 01/30/2002 08:00am

    Originally posted by: Ulrike Scheibner

    I'm using CSplitterBar in my dialog. There are two splitter bars around a button. On the left hand side is a tree control. A vertical splitter bar separates the tree control and the button. On bottom is another tree control. A horizontal splitter bar separates the tree control and the button. It looks like Outlook.
    When I move the vertical splitter bar right and the horizontal splitter bar up (both splitter bars are overlapped in a range) the display isn't correct. The vertical splitter bar isn't drawn completely. (A screenshot would explain the problem better.)
    Is this problem known or does anybody know a solution?

  • How to restore "CSplitterWnd"?

    Posted by Legacy on 10/31/2001 08:00am

    Originally posted by: Henry

    "CSplitterWnd" can creat in "Frame::OnCreateClient",
    and can destroy by "DeleteView","DeleteRow".

    How to restore it?

  • Buggy Code

    Posted by Legacy on 05/31/2001 07:00am

    Originally posted by: Colin MacKenzie

    Problems using as horizontal splitter between two static derived controls.

    No ability to set splitter range - though a simple func can be written. Range is also computed in error. It thinks 100 pixels is the max for the top window?????

    Right pane is not resized properly, its bottom member is not set to bottom of window. However, it does set it to the same as the top member on creation???? (why)

    Sorry, making my own...

  • little flicker fix - stop splitter being dragged outside of surrounding panes

    Posted by Legacy on 02/14/2001 08:00am

    Originally posted by: Jon Erdman



    i noticed some flicker tho, so i added a little fix to keep the splitter bars from being dragged past the edges of their associated left and right (or top and bottom) controls, thus when the windows are redrawn, you don't have to invalidate the whole dialog, just the left and right (or top and bottom :) windows. = less flicker.

    only needed to change 2 functions, here are the changes (lines preceeded with > are new):

    here i limit the dragged bar the the client area of its associated windows:

    void CSplitterBar::DrawDraggingBar(CPoint point,DRAGFLAG df)
    > CRect lrc, rrc;
    > m_pwndLeftPane->GetClientRect(lrc);
    > m_pwndRightPane->GetClientRect(rrc);

    > m_pwndLeftPane->ClientToScreen(&lrc);
    > m_pwndRightPane->ClientToScreen(&rrc);


    > if (point.y > rrc.bottom)
    > point.y = rrc.bottom;
    > else if (point.y < lrc.top)
    > point.y = lrc.top;

    > if (point.x > rrc.right)
    > point.x = rrc.right;
    > else if (point.x < lrc.left)
    > point.x = lrc.left;

    ... the rest of this function is unchanged ...


    void CSplitterBar::MovePanes()
    ... most of this is unchanged
    ... only difference is right here at the bottom:

    //repaint client area
    //GetParent()->Invalidate(); //! causes flicker

    > m_pwndLeftPane->Invalidate();
    > m_pwndRightPane->Invalidate();

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date