- 先创建四个formview类型的对话框,ID为IDD_FORMVIEW0,IDD_FORMVIEW1,IDD_FORMVIEW2,IDD_FORMVIEW3。
- 给四个对话框添加类,继承基类为CFormView,类名为CMyFormView0,CMyFormView1,CMyFormView2,CMyFormView3。
- (我的主对话框类为CRuanjian4Dlg)在CRuanjian4Dlg.h中的public下添加代码
CFrameWnd *m_pMyWnd;
CSplitterWnd m_SplitterWnd;
CSplitterWnd m_SplitterWnd2;
CSplitterWnd m_SplitterWnd3;
- 在CRuanjian4Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 中添加
int CRuanjian4Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
//CDialog::OnInitDialog();
ShowWindow(SW_SHOWMAXIMIZED);//最大化屏幕
CString strMyClass = AfxRegisterWndClass(CS_VREDRAW |CS_HREDRAW,
::LoadCursor(NULL, IDC_ARROW),
(HBRUSH) ::GetStockObject(WHITE_BRUSH),
::LoadIcon(NULL, IDI_APPLICATION));
// Create the frame window with "this" as the parent
CRect rect;
GetClientRect( &rect );
int w = rect.Width();
int h = rect.Height();
m_pMyWnd = new CFrameWnd;
m_pMyWnd->Create(strMyClass,_T(""), WS_CHILD,rect, this);
m_pMyWnd->ShowWindow(SW_SHOW);
if (m_SplitterWnd.CreateStatic(m_pMyWnd,2,1) == NULL) //1行2列
{
return -1;
}
m_SplitterWnd.CreateView(1,0, RUNTIME_CLASS(CMyFormView0),CSize(w,h/8),NULL);//第二行宽w,高h/7
m_SplitterWnd.SetColumnInfo(0, w, 20);
m_SplitterWnd.SetRowInfo(0,7*h/8, 20);
m_SplitterWnd.SetRowInfo(1,h/8, 20);
if(m_SplitterWnd2.CreateStatic(&m_SplitterWnd,1,2,WS_CHILD|WS_VISIBLE,m_SplitterWnd.IdFromRowCol(0,0)) == NULL)
{
return -1;
}
m_SplitterWnd2.CreateView(0,0, RUNTIME_CLASS(CMyFormView1),CSize(5*w/7,7*h/8), NULL);
if(m_SplitterWnd3.CreateStatic(&m_SplitterWnd2,2,1,WS_CHILD|WS_VISIBLE,m_SplitterWnd2.IdFromRowCol(0,1)) == NULL)
{
return -1;
}
m_SplitterWnd3.CreateView(0,0, RUNTIME_CLASS(CMyFormView2),CSize(2*w/7,14*h/40), NULL);
m_SplitterWnd3.CreateView(1,0, RUNTIME_CLASS(CMyFormView3),CSize(2*w/7,21*h/40), NULL);
return 0;
}
- 不要忘记在顶部添加.h文件
#include "MyFormView0.h"
#include "MyFormView1.h"
#include "MyFormView2.h"
#include "MyFormView3.h"
- 在CRuanjian4Dlg::OnInitDialog()中添加
CRect rect;
GetWindowRect(&rect);
ScreenToClient(&rect);
m_pMyWnd->MoveWindow(&rect);
m_pMyWnd->ShowWindow(SW_SHOW);
- 运行后如图