Simple Splitter

 

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

m_wndSplitterBar.SetPanes(&m_wndTree,&m_wndList);

 

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.

Note:

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)



Comments

  • Nike Air Max+instagram, will you hold the color to step on your feet!

    Posted by madytreathy on 04/20/2013 07:20am

    Call to mind in 2008, if not earlier, when Nike launched on of the separated shoe color projects, the war cry "Scion Your Colours", "Nike PhotoiD" layout, [url=http://markwarren.org.uk/property-waet.cfm]nike air max 90[/url] reply has not been as enthusiastic as expected. Have in mind, 2008 Canon IXUS 80 IS Digital card arcade but purely 8 million pixels, Nokia, the mobile phone retail is the exclusively administration, NikeiD was boost to color in the photos as a basis quest of sneakers duty color, although gripping, but does bother some. Instagram which cause this article hold up to ridicule and elemental, Nike PHOTOiD homeopathic upgrade customization services, recently [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache free[/url] released a new plan. That such iD can you implement pictures as instagram account shoe color, the meanwhile make available Nike Air Max shoes and Nike Air Max 1, Nike Feeling Max 90 953 options. Interested in children's shoes, you [url=http://markwarren.org.uk/goodbuy.cfm]nike free uk[/url] can without exception conform with each other's legitimate website photoid.Nike.com, in beyond to skim through other people's creative sweat, or you can hear to upload your own instagram photo, base your own Nike Air Max.

    Reply
  • Right drag fix

    Posted by christig on 12/25/2004 11:05pm

    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

    Reply
  • Saying thanks then another big question.

    Posted by Legacy on 02/17/2004 12: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.


    Reply
  • Can it be used in an ATL composite control?

    Posted by Legacy on 10/10/2003 12: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.

    Reply
  • Invisible Splitter Bars Please!

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

    Originally posted by: Jimmy

    Hi,

    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.

    Thanks!

    Reply
  • Cursor disappered when using staticly linked MFC

    Posted by Legacy on 11/12/2002 12: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?

    Reply
  • dragger drawn outside pane

    Posted by Legacy on 10/17/2002 12: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;
    m_pwndLeftPane->GetWindowRect(left);
    m_pwndRightPane->GetWindowRect(right);
    total = left | right;
    CPoint temp = pt;
    ClientToScreen(&temp);
    if (total.PtInRect(temp))
    return TRUE;
    else
    return FALSE;
    }


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

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

    Reply
  • Overlapping Splitter Bars

    Posted by Legacy on 01/30/2002 12: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?

    Reply
  • How to restore "CSplitterWnd"?

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

    Originally posted by: Henry

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

    How to restore it?

    Reply
  • Buggy Code

    Posted by Legacy on 05/31/2001 12: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...

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds