最近做的工作里包括了MFC单文档的分割,过程很简单,但还是想记录下来。
如下进行了单文档分割为三个视图的操作:
1 利用类向导建立额外的两个view 基类是CView
2 在mainFirm.cpp中包含两个新加的view的头文件
3 在mainFirm.h中添加分割窗口的成员变量CSplitterWnd m_wndSplitter;
4 在mainFirm.cpp中重写oncreateclient
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { // TODO: Add your specialized code here and/or call the base class CRect rc; GetClientRect(&rc); //将窗口分为三列一行 if (!m_wndSplitter.CreateStatic(this, 1, 3)) return FALSE; //指定每个窗口的位置及初始大小 if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CthreadView), CSize(rc.Width()/3, rc.Height()), pContext) || !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CthreadView1), CSize(rc.Width()/3, rc.Height()), pContext)|| !m_wndSplitter.CreateView(0, 2, RUNTIME_CLASS(CthreadView1), CSize(rc.Width()/3, rc.Height()), pContext)) { m_wndSplitter.DestroyWindow(); return FALSE; } return TRUE; //CWnd*m_pwnd = (CWnd*)m_wndSplitter.GetPane(0,0); //CWnd *m_pwnd1= (CWnd*)m_wndSplitter.GetPane(0,1); m_pwnd = (CWnd*)m_wndSplitter.GetPane(0,0); m_pwnd1= (CWnd*)m_wndSplitter.GetPane(0,1); //return CFrameWnd::OnCreateClient(lpCreateStruct, pContext);}