CSplitDialog for Dialog based Applications | CodeGuru

CSplitDialog for Dialog based Applications

Environment: VC++ 6.0, Win9x/NT/2000/XP I’ve been using some other similar classes before but I got to a point where they weren’t enough to do the job I needed. So I wrote down this class and I guess some people might find it useful. There are 4 files that are needed for this to work: Pane.h […]

Written By
CodeGuru Staff
CodeGuru Staff
Nov 15, 2001
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: VC++ 6.0, Win9x/NT/2000/XP

I’ve been using some other similar classes before but I got to a point where they weren’t enough to do the job I needed. So I wrote down this class and I guess some people might find it useful.

There are 4 files that are needed for this to work:

Pane.h

Pane.cpp     These define the calss CPane

SplitDialog.h

SplitDialog.cpp     These define the class CSplitDialog

All you need to do is derive your Dialog from CSplitDialog instead of CDialog and do some initialization steps like this:

BOOL CSplitDialogDemoDlg::OnInitDialog()
{
  CSplitDialog::OnInitDialog();

  // Set the icon for this dialog. The framework does
  // this automatically when the application’s main
  // window is not a dialog
  SetIcon(m_hIcon, TRUE);   // Set big icon
  SetIcon(m_hIcon, FALSE);  // Set small icon

  //create the panes
  m_PaneMain = CreatePane(CPane::ST_VERTICAL);
  m_PaneLeft = CreatePane(CPane::ST_HORIZONTAL,m_PaneMain,1,FALSE);
  m_PaneRight = CreatePane(CPane::ST_HORIZONTAL,m_PaneMain,2);
  //assign the controls
  SetPaneWnd(m_PaneLeft,&m_combo,1);
  SetPaneWnd(m_PaneLeft,&m_treectrl,2);
  SetPaneWnd(m_PaneRight,&m_listbox,1);
  SetPaneWnd(m_PaneRight,&m_listctrl,2);
  SetTopOffset(30);
  Initialize();
  return TRUE; // return TRUE unless you set the focus to a control
}

So, from the code above we can see that the major functions are CreatePane and SetPaneWnd. In the beginning, there are no panes, so you call CreatePane with only a style (Vertical or Horizontal). This will create the main pane in which you should add other panes. Panes can be nested as you can see. To nest panes just call CreatePanes again and pass the result returned by a previous CreatePanes to it to tell it that this will be the parent of the new pane. Now the numbers at the 1/2 tell the funtion which pane is being created. Every pane contains 2 subitems, a left item and a right item. An item can be either a nested Pane or a CWnd*. SetPaneWnd allows you to set that item to be a CWnd*. 1 tells the functions that you are setting up the left pane (in vertical style or top in horizontal style) or the right pane (same…). Now once everything is set, you can call an optional SetMainRect or SetxOffset (x can be Top,Right,Bottom,Left) to setup the main pane’s area. Finally after everything is done, you will need to call Initialize() to snap the controls to where they need to be at startup.

It’s a good idea to keep a pointer to ever pane you’ve created in case you would like to hide it or hide one of it’s items. This can be easily done by calling the function:

BOOL ShowPane(CPane *pPane, BOOL bShow = TRUE, int nWhich = 0);

Where pPane is the pane you want to show/hide, bShow will be set to FALSE if you’re hiding and TRUE if you’re showing, nWhich will tell the pane Which side to hide, 1 for left, 2 for right.

Take a look at the demo program, it should be very simple to use.

And to wrap up a bit, here’s the function prototypes that you would need to use:

  void Initialize();
  CPane *CreatePane( int nSplitType,
                     CPane *pParent = NULL,
                     int nWhich = 0,
                     BOOL bSizeableControls = TRUE);
  BOOL SetPaneWnd( CPane *pPane,
                   CWnd *pWnd,
                   int nWhich,
                   int minWidth = 100,
                   int minHeight = 100,
                   int Width = 0,
                   int Height = 0);
  BOOL ShowPane( CPane *pPane,
                 BOOL bShow = TRUE,
                 int nWhich = 0);
  void SetMainRect(RECT rect);
  void SetMainRect(int X, int Y, int nWidth, int nHeight);
  void SetTopOffset(int topOffset);
  void SetLeftOffset(int leftOffset);
  void SetRightOffset(int rightOffset);
  void SetBottomOffset(int bottomOffset);

I’m sorry if my explanation isn’t all that good, I’ve always been lousy at teaching people stuff… 😐

Hope this helps…

Downloads

Download demo project – 24 Kb

Download source – 8 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.