用MFC开发一个软件界面中需要拆分多个试图窗口时,如下图所示:
CSplitterWnd类主要用在创建一个拆分试图窗口。通常嵌入在框架窗口中(CMainFrame)
创建步骤:
1.在框架类(CMainFrame)中定义一个CSplitterWnd成员;
2.重载父框架类中函数;
3.在OnCreateClient()函数中调用CSplitterWnd类的Create或CreateStatic()函数;
例子:
CSplitterWnd m_wndSplitter;
BOOL CChildFrame::OnCreateClient( LPCREATESTRUCT lpcs,
CCreateContext* pContext){ BOOL bCreateSpltr = m_wndSplitter.CreateStatic( this, 2, 1);// COneView and CAnotherView are user-defined views derived from CMDIView
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(COneView), CSize(0,0), pContext); m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CAnotherView), CSize(0,0), pContext); return (bCreateSpltr);}或者:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{ // TODO: Add your specialized code here and/or call the base class if (!m_wndSplitter.CreateStatic(this, 1, 2)) return FALSE;if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(160, 200), pContext) ||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CTestView), CSize(100, 200), pContext)) { m_wndSplitter.DestroyWindow(); return FALSE; } return TRUE;}