Show/Hide Static Panes

MFC static splitter windows have a significant limitation. Their panes can't be hidden or shown dynamically. To solve the problem I overrode the CSplitterWnd. The new class can hide a splitter window column. Sure, it's only one approach to the problem, but it's a good example anyway.

// splitex.h
// (c) 1997, Oleg G. Galkin

class CSplitterWndEx : public CSplitterWnd
   int m_nHidedCol;    // hide column number, -1 if all columns
                       // are shown


   void ShowColumn();
   void HideColumn(int colHide);

// ClassWizard generated virtual function overrides

// Generated message map functions
      // NOTE - the ClassWizard will add and remove member
      //        functions here.


// splitex.cpp
// (c) 1997, Oleg G. Galkin

#include "stdafx.h"
#include "splitex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;

// CSplitterWndEx

CSplitterWndEx::CSplitterWndEx() :

void CSplitterWndEx::ShowColumn()
   ASSERT(m_nCols < m_nMaxCols);
   ASSERT(m_nHidedCol != -1);

   int colNew = m_nHidedCol;
   m_nHidedCol = -1;
   int cxNew = m_pColInfo[m_nCols].nCurSize;
   m_nCols++;    // add a column
   ASSERT(m_nCols == m_nMaxCols);

   // fill the hidden column
   int col;
   for (int row = 0; row < m_nRows; row++)
      CWnd* pPaneShow = GetDlgItem(
         AFX_IDW_PANE_FIRST + row * 16 + m_nCols);
      ASSERT(pPaneShow != NULL);

      for (col = m_nCols - 2; col >= colNew; col--)
         CWnd* pPane = GetPane(row, col);
         ASSERT(pPane != NULL);
         pPane->SetDlgCtrlID(IdFromRowCol(row, col + 1));

      pPaneShow->SetDlgCtrlID(IdFromRowCol(row, colNew));

   // new panes have been created -- recalculate layout
   for (col = colNew + 1; col < m_nCols; col++)
      m_pColInfo[col].nIdealSize = m_pColInfo[col - 1].nCurSize;
   m_pColInfo[colNew].nIdealSize = cxNew;

void CSplitterWndEx::HideColumn(int colHide)
   ASSERT(m_nCols > 1);
   ASSERT(colHide < m_nCols);
   ASSERT(m_nHidedCol == -1);
   m_nHidedCol = colHide;

   // if the column has an active window -- change it
   int rowActive, colActive;
   if (GetActivePane(&rowActive, &colActive) != NULL &&
       colActive == colHide)
      if (++colActive >= m_nCols)
         colActive = 0;
      SetActivePane(rowActive, colActive);

   // hide all column panes
   for (int row = 0; row < m_nRows; row++)
      CWnd* pPaneHide = GetPane(row, colHide);
      ASSERT(pPaneHide != NULL);
         AFX_IDW_PANE_FIRST + row * 16 + m_nCols);

      for (int col = colHide + 1; col < m_nCols; col++)
         CWnd* pPane = GetPane(row, col);
         ASSERT(pPane != NULL);
         pPane->SetDlgCtrlID(IdFromRowCol(row, col - 1));
   m_pColInfo[m_nCols].nCurSize = m_pColInfo[colHide].nCurSize;

BEGIN_MESSAGE_MAP(CSplitterWndEx, CSplitterWnd)
   // NOTE - the ClassWizard will add and remove mapping macros here.


  • Dr

    Posted by wang gang on 03/05/2015 06:42pm

    Very usefule!Thanks

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

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Power and Automation Equipment makers face constrained CAPEX, equipment interoperability issues, and process inefficiencies. However, they can take advantage of secure Internet of Things (IoT) intelligent devices and systems to make better business decisions around asset utilization and performance, while simultaneously optimizing equipment interoperability and services efficiency. Watch this brief video to see how you can unlock the full potential of your assets and value chain.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date