Virtual Developer Workshop: Containerized Development with Docker
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 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:
2. Secondly, create the m_wndSplitterBar object in the InitDialog function:
//Create a splitter bar
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)