使用MFC创建分割视图:
使用向导Ctrl+W创建一个CMyView
可使用Ctrl+W呼出向导进行
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { // TODO: Add your specialized code here and/or call the base class return CFrameWnd::OnCreateClient(lpcs, pContext); }
在CMainFrame的文件开始处包含MyView.h #include "MyView.h"
现在开始创建一个一行两列的窗体
重载函数现在为
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { // TODO: Add your specialized code here and/or call the base class if(!m_wndSplitter1.CreateStatic(this,1,2)) return FALSE; if(!m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CMyView),CSize(500,600),pContext)) return FALSE; if(!m_wndSplitter1.CreateView(0,1,RUNTIME_CLASS(CMyView),CSize(100,600),pContext)) return FALSE; return TRUE; }得到的分割视图为
5、对右边一行的视图再次进行分割
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { // TODO: Add your specialized code here and/or call the base class if(!m_wndSplitter1.CreateStatic(this,1,2)) return FALSE; if(!m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CMyView),CSize(500,600),pContext)) return FALSE; //再次分割 if(!m_wndSplitter2.CreateStatic(&m_wndSplitter1,2,1,WS_CHILD|WS_VISIBLE,m_wndSplitter1.IdFromRowCol(0,1))) return FALSE; //右方视图创建 if(!m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CMyView),CSize(100,200),pContext)) return FALSE; if(!m_wndSplitter2.CreateView(1,0,RUNTIME_CLASS(CMyView),CSize(100,400),pContext)) return FALSE; return TRUE; }