Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5833409
  • 博文数量: 671
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 7310
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-14 09:56
文章分类

全部博文(671)

文章存档

2011年(1)

2010年(2)

2009年(24)

2008年(271)

2007年(319)

2006年(54)

我的朋友

分类:

2007-09-12 17:26:32

 

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

 

本地下载:

 

文件: splitdialogdemo.zip
大小: 24KB
下载: 下载

阅读(1432) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~