As you see, you can arbitrarily add DOC/View, and all the view can be resized.
Why I Write this class?
My company asked me to make a COM dialog supporting multi_Doc/View. Because this is a COM based dialog, I can't make it using this Single or Mulit_Doc Doc/View. I looked for a solution in The Code Project, Code Guru etc., but I couldn't find a suitable class and sample, so I did it myself.
What's this about?
This demo only implements the base function: you can add the Doc / view, resize the View by dragging the splitter. Here, using iterator, notice all the view changing size. This can be done better :-), and this method has some bug. For example, I can't proportionately scale the sub_split's view� I will fix it. :-)
What classes are part of this?
CSplitterControl
This class is like the Split, but not derived form the CSplitterWnd
.
CDisplayView
View's base class, here all view resizing must derive form it.
How to using this class
-
Add this files into your project
SplitterControl.h
SplitterControl.cpp
DisplayView.h
DisplayView.cpp
-
Add some code in your project
#include <VECTOR>
#include "SplitterControl.h"
#include "DisplayView.h"
using namespace std;
class CMyDlgDlg: public CDialog
{
void UpdateRect(CSplitterControl *pSplitter);
CDisplayView *AddRootView(UINT docNum, UINT viewNum,CRect
rect,CSplitterControl *splitter);
void AddView(UINT docNum,UINT viewNum,UINT type,
CSplitterControl *splitter,
CView *pCurView);
CSplitterControl m_pSplit;
CCreateContext m_pContext;
};
-
Into the CMyDlgDlg's dialog designer
-
Copy the function implementation code from the demo project.
void CMyDlgDlg::AddView(UINT docNum, UINT viewNum,UINT type,
CSplitterControl *splitter,CView *pCurView)
{
}
CDisplayView *CMyDlgDlg::AddRootView(UINT docNum, UINT viewNum,
CRect rect,CSplitterControl *splitter)
{
}
void CMyDlgDlg::UpdateRect(CSplitterControl *pSplitter)
{
}
BOOL CMyDlgDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rc;
GetDlgItem(IDC_STA_SPLIT)->GetWindowRect(rc);
ScreenToClient(rc);
m_pSplit.Create(WS_CHILD | WS_VISIBLE,rc,this,IDC_STA_SPLIT);
m_pSplit.SetRange(300, 300, -1);
GetDlgItem(IDC_STA_VIEW)->GetWindowRect(rc);
ScreenToClient(rc);
m_pSplit.AddRootView(0,1,rc);
m_pSplit.ShowWindow(SW_HIDE);
return TRUE;
}
-
In the SplitterControl.cpp, add the Dialog's head file
#include "MyDlg.h" /*The application class */
#include "MyDlgDlg.h" /*the dialog class */
I am Chinese and finish my school life last month, my English is very poor, so this article has some language error :-). I am a devoted reader of CodeProject, thanks everybody for helping me. Thanks CodeProject, thanks C++.