
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...
----------------------------------------
从国外网站上转载的,原出外http://www.codeguru.com/article.php/c4973,源文件可以原地址下载
本文介绍了一个自定义面板类,用于在对话框中实现多面板布局。通过继承自定义类并调用特定函数,开发者可以轻松地创建、配置和管理不同类型的面板。演示了如何初始化面板、设置窗口、创建子面板以及调整布局参数,提供了简化多面板应用开发的解决方案。
9234

被折叠的 条评论
为什么被折叠?



