CSplitDialog for Dialog based Applications


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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.cpp     These define the calss CPane
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()

  // 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



  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...


Download demo project - 24 Kb
Download source - 8 Kb


  • resizing breaks this

    Posted by Legacy on 09/18/2003 07:00am

    Originally posted by: Gene Sewell

    I was able to get this to work nicely.

    However, I also wanted to implement resizing. As soon as I started moving the controls, everything broke.

    Any suggestions for how to add resizing capability?

    Thanks in advance...

  • Dialog not open when resource in a DLL

    Posted by Legacy on 05/08/2003 07:00am

    Originally posted by: Crercio O. Silva

    I use a resource only DLL which allows me to translate the application to other languages and just load the correct language DLL in the application InitInstance. The problem is that everything works ok except for the CSplitDialog. It doesn't show up.
    Any help?

  • Splitter in property pages

    Posted by Legacy on 02/21/2002 08:00am

    Originally posted by: vasanth

    The splitter is really cool. But i need splitter in the property page. Is there any way of doing that?

  • CpropertyPage

    Posted by Legacy on 01/25/2002 08:00am

    Originally posted by: David Smulders

    Great class but is there a way that I can split on a CpropertyPage with this class?

    Gr, David

  • where is CListCtrl scroll ?

    Posted by Legacy on 01/14/2002 08:00am

    Originally posted by: ran wainstein

    Your class does not show the scroller in clistctrl
    when runninig release mode ....help

  • CListCtrl

    Posted by Legacy on 12/15/2001 08:00am

    Originally posted by: David

    My CListCtrl Scroll does show with your class??
    Hou can that be?

    Gr, David

  • Updates note

    Posted by Legacy on 11/17/2001 08:00am

    Originally posted by: Georges Kanaan

    Hi guys,
    while i was in a hurry to send the class to codeguru i skipped a few bugs... I've fixed them i think all and i've updated the files outside. However, the Demo project has a few missing parts in the code that i disabled for the purpose of testing and forgot to uncomment before updating the post and i think it's a bit annoying to resend the updates again for something easy in the demo, you just need to uncomment a few lines:
    In InitDialog()
    -SetTopOffset and SetLeftOffset are commented, uncomment them.
    Right after those there's 2 lines ShowPane(FALSE), delete/comment these, they hide 2 controls and that's it.
    Sorry for the trouble, hope you liked the classe...

  • Amazing work

    Posted by Legacy on 11/14/2001 08:00am

    Originally posted by: Crercio O. Silva

    I've been looking for something like for ever. I have been testing many controls, like you did, and they did not seem to fit my need. Not anymore.
    Congratulations for the excellent work.

  • Doc/View architecture?

    Posted by Legacy on 11/13/2001 08:00am

    Originally posted by: Peter Ritchie

    Why not use the existing framework's use of a doc/view architecture. It's been around a while and gives you roughly the same functionality (as well as adding inherent menu support, etc.)

    You can do the same thing with ATL and MFC with an integrated resource editor and wizard to avoid most of the implementation details.

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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