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.
- 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
Right drag fix
Posted by christig on 12/25/2004 11:05pmvoid 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
ReplySaying thanks then another big question.
Posted by Legacy on 02/17/2004 12:00amOriginally 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.
ReplyCan it be used in an ATL composite control?
Posted by Legacy on 10/10/2003 12:00amOriginally 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.
ReplyInvisible Splitter Bars Please!
Posted by Legacy on 02/28/2003 12:00amOriginally 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!
ReplyCursor disappered when using staticly linked MFC
Posted by Legacy on 11/12/2002 12:00amOriginally 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:00amOriginally 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:00amOriginally 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.
ReplyWhen 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 12:00amOriginally posted by: Henry
"CSplitterWnd" can creat in "Frame::OnCreateClient",
and can destroy by "DeleteView","DeleteRow".
How to restore it?
ReplyBuggy Code
Posted by Legacy on 05/31/2001 12:00amOriginally 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...
Replylittle flicker fix - stop splitter being dragged outside of surrounding panes
Posted by Legacy on 02/14/2001 12:00amOriginally posted by: Jon Erdman
ReplyLoading, Please Wait ...