用VS08程序向导,单文档程序,默认设置生成的。工程名为3view;
其中默认生成的视图类CMy3viewView,对应3viewView.h,3viewView.cpp;
在Resourse View添加个新对话框,在对话框的属性中,Border设置成None;Style设置成Child;
生成的新类中Base class设置为CFormView; 本程序中定义类名为CDefFormView;
默认生成的文档类为:3viewDoc.h,3viewDoc.cpp;
在主框架头文件MainFrm.h中添加如下头文件; //为了调用程序默认的视类CMy3viewView;
#include "3viewDoc.h"
#include "3viewView.h"
并添加如下变量
CSplitterWnd m_wndSplitter;
CSplitterWnd m_wndSPlitterTB;
CSplitterWnd m_wndSPlitterTB2;
BOOL m_is_spilit //用来判断分割窗口是否成功,做为窗口自适应大小的变量
并重载OnCreateClient函数
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
CRect ct;
GetClientRect(&ct);
//主框架左右分成1行3列
m_wndSplitter.CreateStatic(this,,); //在m_wndSplitter的第1行第1列分割区成2行1列
m_wndSPlitterTB.CreateStatic(&m_wndSplitter,,,WS_CHILD|WS_VISIBLE,m_wndSplitter.IdFromRowCol(,));
//在m_wndSplitter的第1行第2列分割区成2行1列
m_wndSPlitterTB2.CreateStatic(&m_wndSplitter,,,WS_CHILD|WS_VISIBLE,m_wndSplitter.IdFromRowCol(,)); //在m_wndSPlitterTB中创建第1行第1列视图
m_wndSPlitterTB.CreateView(,,RUNTIME_CLASS(CDefFormView),CSize(ct.Width()/,ct.Height()/),pContext);
//在m_wndSPlitterTB中创建第2行第1列视图
m_wndSPlitterTB.CreateView(,,RUNTIME_CLASS(CDefFormView),CSize(ct.Width()/,ct.Height()/),pContext); //在m_wndSPlitterTB2中创建第1行第1列视图
m_wndSPlitterTB2.CreateView(,,RUNTIME_CLASS(CDefFormView),CSize(ct.Width()/,ct.Height()/),pContext);
//在m_wndSPlitterTB2中创建第2行第1列视图
m_wndSPlitterTB2.CreateView(,,RUNTIME_CLASS(CMy3viewView),CSize(ct.Width()/,ct.Height()/),pContext);
//在m_wndSPlitterTB2中创建第3行第1列视图
m_wndSPlitterTB2.CreateView(,,RUNTIME_CLASS(CDefFormView),CSize(ct.Width()/,ct.Height()/),pContext); //在m_wndSPlitter中创建第1行第3列的视图
m_wndSplitter.CreateView(,,RUNTIME_CLASS(CMy3viewView),CSize(ct.Width()/,),pContext);
m_wndSplitter.SetColumnInfo(0,ct.Width()/3,50);
m_wndSplitter.SetColumnInfo(1,ct.Width()/3,50);
m_wndSplitter.SetColumnInfo(2,ct.Width()/3,50);
//获取对应视图的对象
CMy3viewView* view = (CMy3viewView *)m_wndSplitter.GetPane(,);
CDefFormView* view2 = (CDefFormView*)m_wndSPlitterTB.GetPane(,); return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}
重载OnSize函数:(主框架大小变化是分割窗口自适应大小)
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy); // TODO: Add your message handler code here
if(m_is_spilit)
{
CRect ct;
GetClientRect(&ct); m_wndSplitter.SetRowInfo(,ct.Height(),);
m_wndSplitter.SetColumnInfo(,ct.Width()/,);
m_wndSplitter.SetColumnInfo(,ct.Width()/,);
m_wndSplitter.SetColumnInfo(,ct.Width()/,); m_wndSPlitterTB.SetRowInfo(,ct.Height()/,);
m_wndSPlitterTB.SetRowInfo(,ct.Height()/,); m_wndSPlitterTB2.SetRowInfo(,ct.Height()/,);
m_wndSPlitterTB2.SetRowInfo(,ct.Height()/,);
m_wndSPlitterTB2.SetRowInfo(,ct.Height()/,); m_wndSplitter.RecalcLayout(); }
}
生成的程序如图显示: