分类:
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...
本地下载:
|