Invisible Splitter Window

Similar to “Windows Explorer” with Web Content Enabled

.

Environment: VC6, Windows 2000

When we want to create more than one view in the same view, we go for split windows. What if we don’t want that splitter to be visible? (Like what we have in “Windows Explorer,” but with Web content enabled.)

The class that I have provided here helps you to successfully hide the splitters. Making the splitter invisible by calling CWnd::ShowWindow(FALSE) won’t work because Views are Child windows of the Splitter. When the parent is hidden, the child cannot be visible.

The only way is to override the OnDrawSplitter() function. There is a flag that decides the splitter to be visible or invisible (this is set in the constructor). Here we go…

void CSplitterWndEx::OnDrawSplitter(CDC *pDC, ESplitType nType,
      const CRect &rectArg)
{
  if (pDC == NULL)
  {
    RedrawWindow(rectArg, NULL, RDW_INVALIDATE|RDW_NOCHILDREN);
    return;
  }
  /**
  * If you want to see the splitter window,
  * Use the base class's drawing funcion;
  * otherwise, fill the Splitter with the View's color.
  */
    if(m_Visible)
    {
        CSplitterWnd::OnDrawSplitter(pDC,nType,rectArg);
        return;
    }
  ASSERT_VALID(pDC);
  CRect rect = rectArg;
  CPen WhitePen;
  WhitePen.CreatePen( PS_SOLID,
                      PEN_WIDTH,
                      GetSysColor(COLOR_WINDOW));
  pDC->SelectObject(&WhitePen);
  pDC->Rectangle(rect);
}

The next step is to disable the resizing capability of the splitter window. To disable those functionalities, override the following:

  • CSplitterWnd::OnMouseMove(UINT /*nFlags*/, CPoint pt);
  • CSplitterWnd::StartTracking(int ht);
  • CSplitterWnd::OnDrawSplitter(CDC* pDC, ESplitType nType,const CRect& rectArg);
  • CSplitterWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  • CSplitterWnd::OnMouseWheel(UINT fFlags, short zDelta, CPoint point);

This is a very simple way to hide the splitter window.

When using the splitter, call the construcor with FALSE to hide it and TRUE or without any parameter for a normal splitter window.

For an invisible splitter, use this code:

  CSplitterWndEx splitter(FALSE);    //Set visible to FALSE.
  splitter.CreateStatic(this,1,2);
  splitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),
      CSize(120,120),pContext);
  splitter.CreateView(0,1,RUNTIME_CLASS(CTextView),
      CSize(128,0),pContext);

For a visible splitter, use this code:

  CSplitterWndEx splitter(TRUE);    // Set visible to TRUE
// (or)

CSplitterWndEx splitter; // Default is TRUE.
// Use the splitter.

splitter.CreateStatic(this,1,2);
splitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),
CSize(120,120),pContext);
splitter.CreateView(0,1,RUNTIME_CLASS(CTextView),
CSize(128,0),pContext);

Downloads

Download demo project - 8.00 Kb

Download source - 32.0 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read