Creating Thin-Framed Splitter Windows


This article was contributed by Jens Winslow.

Environment: Windows and Dialogs, VC++

The credit for this solution goes to Markus Plaum, who was the one who actually figured out how to do this. Thanks, Markus.

While creating a program to draw a data view with a scale, using a splitter window with scale in top of the pane, and data in the bottom, I was frustrated in my inability to avoid the “fat” splitter border between the two view panes (and I did not want user to resize the scale view). After trying many approaches based on examples from books and CodeGuru, I was ready to give up. Luckily, a friend of mine had solved this problem in the past.

Somehow, he had determined that the CSplitterWnd class has several member variables that determine the frame of the splitter border. These do not appear to be documented, but if one steps through the constructor CSplitterWnd::CSplitterWnd() in …MFC/Src\Winsplit.cpp, they are right there.

All I needed to do was to derive my own splitter class and modify these member variables to achieve my desired effect.

CThinFrameSplitterWnd : CSplitterWnd

CThinFrameSplitterWnd::CPaneSplitter()
{
  m_cxSplitter=PANE_BORDER;     // = 1
  m_cySplitter=PANE_BORDER;     // = 1
  m_cxBorderShare=PANE_SHARE;   // = 0
  m_cyBorderShare=PANE_SHARE;   // = 0
  m_cxSplitterGap=PANE_GAP;     // = 1
  m_cySplitterGap=PANE_GAP;     // = 1

}

Replacing the CSplitterWnd::HitTest(CPoint pt) const function allowed me to ignore the mouse position over the frame to avoid user resizing, which was both desired and necessary—my changes to m_cxSplitter and so forth cause an assertion if the user tries to resize.

int CThinFrameSplitterWnd::HitTest(CPoint /*pt*/) const
{
  ASSERT_VALID (this);
  return 0;       // don't let the user see the mouse hits
}

Below is an example where I have created a horizontal split frame (CChildFrame), with the left-hand frame having a scale_data splitter window, and the right-hand frame having two splitter windows, each with a scale_data splitter window. The right picture shows the effect of using CThinFrameSplitter instead of CSplitterWnd in a scale_data splitter window.

I hope this may save someone the time it took Markus and me to figure this out.

Jens Winslow

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read