CSSplitter: Splitter with the Ability to Save/Restore Its Position

Introduction

CSSplitter is a class derived from CStatic. CSSplitter provides splitter functionality (in other words, sizing functionality) for dialogs, property sheets, and any other CWnd-derived windows.

This class can work both with controls from dialog resources and those created on-the-fly. Besides, this splitter control works within the rectangular area, whose dimensions are defined by the user of the class. You also can assign margins for the splitter rectangular area beyond which the splitter is not allowed to move. To cancel splitting, the end-user can push the ESC key. Using the ESC key is convenient for CFormView-based applications and other applications, like CView based ones, but it is unusable for dialogs. CSSplitter also hides/shows controls using the ShowWindow() and MoveWindow() methods without deleting and re-creating.

Moreover, splitters created by CSSplitter save their positions into the Registry and then restore them the next time a window containing controls is created. It is very important that splitter panes can be NESTED.

Using the Code

With the CSSplitter class, you can easily add splitter functionality to your window. Just use the following steps:

  1. Add "SSplitter.cpp" and "SSplitter.h" to the project.
  2. Include "SSplitter.h" in the header file where the controls are defined.
  3. Add a member variable for each splitter pane you want to create:
  4. CSSplitter m_MainSplitterPane;
  5. In the window initialization, create the objects of each splitter pane:
  6. BOOL CTestDlg::OnInitDialog()
    {
    //...
       m_MainSplitterPane.Create(
          WS_CHILD|WS_VISIBLE|WS_BORDER|WS_CLIPCHILDREN|SS_VERT,
          this,               // the parent of the splitter pane
          &m_TreeCtrl,        // left pane
          &m_ListCtrl,        // right pane
          IDC_VERT_SPLITTER,  // this ID is used to save/restore
                              // the splitter position and
                              // therefore it must be unique
                              // within your application
          rect,               // dimensions of the splitter pane
          90,                 // left constraint for splitter
                              // position
          110                 // right constraint for splitter
                              // position
       );
    //...
    

Following is some explanation about the Create() method of the CSSplitter class:

BOOL Create(DWORD dwStyle,
      CWnd* pParentWnd,
      CWnd* pFPane,
      CWnd* pSPane,
      UINT nID,
      const RECT& rc,
      UINT nFConstr = 30,
      UINT nSConstr = 30
   );

Parameters

  • dwStyle: Specifies the splitter pane style.
  • pParentWnd: The pointer to the parent of the splitter pane.
  • pFPane: The pointer to the left pane if dwStyle contains the SS_VERT style and to the top pane if dwStyle contains the SS_HORIZ style.
  • pSPane: The pointer to the right pane if dwStyle contains the SS_VERT style and to the bottom pane if dwStyle contains the SS_HORIZ style.
  • nID: The resource ID. This ID is used to save/restore the splitter position; therefore, it must be unique within your application.
  • rc: Rectangle of the splitter pane.
  • nFConstr: The number of pixels of the left margin (if dwStyle contains the SS_VERT style) and top margin (if dwStyle contains the SS_HORIZ style) beyond which the splitter is not allowed to move. The default value is 30 pixels.
  • nSConstr: The number of pixels of right margin (if dwStyle contains SS_VERT style) and bottom margin (if dwStyle contains SS_HORIZ style) beyond which splitter is not allowed to move. Default value is 30 pixels.

Remarks

Use the SS_VERT style for the vertical splitter and SS_HORIZ for the horizontal splitter. Use WS_CLIPCHILDREN and OnEraseBkgnd to stop flicker during sizing.

To hide/show panes, one can use the HideRightPane()/ShowRightPane(), HideLeftPane()/ShowLeftPane(), and HideBottomPane()/ShowBottomPane() methods. The MakeVertSplitter() and MakeHorizSplitter() methods make the splitter vertical and horizontal, respectively. the SetSplitterPos(int nPos) method sets a new splitter position within its splitter pane.

About Alexander Atamas

PhD in Physics.
Fields of interest: C/C++, GUI application development using VC++ and MFC; databases such as MS SQL Server, MS Access, and MySQL; Web site development.



Downloads

Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Temporary network outages -- even those lasting just a few minutes -- can cripple organizations that rely on local Internet access at remote locations. Failover systems that automatically switch to 4G LTE cellular when landlines go down let organizations maximize uptime, even when the unexpected happens. Read this white paper to learn how 4G failover systems that use standalone gateways supported by a cloud-based management tool are proving to be a solid choice for improved business continuity and productivity …

  • Bonita BPM 7 is here! And for you, an in-depth tour of its innovation. In this webinar, we'll guide you through the brand-new features of this release and demonstrate them live. You will: Discover how business application implementation and maintenance is now even easier, with decoupling of process logic, business data and user interface Learn how to create "living applications" for business processes which present business data in custom views We recommend that you watch the half-hour recording of our …

Most Popular Programming Stories

More for Developers

RSS Feeds

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