在MFC的文档模式中,为了用户界面友好,以多种形式现实用户数据,我们需要切分视图窗口。

 

 

在SDI模式中若需要切分窗口步骤如下:

 

step1: 在CMainFrame类中添加窗口切分变量CSplitterWnd m_wndSplitter, m_wndSplitterRight.

step2:在CMainFrame类中重载CFrameWnd的成员函数OnCreateClient

step2:在OnCreateClient函数中添加如下代码

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class

// Get the client rect of application
CRect rect;
this->GetClientRect(&rect);
// Width of the client rect
int nWidth = rect.right - rect.left;
//height of the client rect
int nHeight = rect.bottom - rect.top;
#define FRACTION 4
// split the view into 1 row 2 cols
m_wndSplitter.CreateStatic(this, 1, 2);
// create a view in 0 row 0 col
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CProjectFormView), CSize(nWidth / FRACTION, 0), pContext);

// split the view in 0 row 1 col into 2 rows 1 col
m_wndSplitterRight.CreateStatic(&m_wndSplitter, 2, 1, WS_CHILD | WS_VISIBLE, m_wndSplitter.IdFromRowCol(0, 1));
// create two views in the subview
m_wndSplitterRight.CreateView(0, 0, RUNTIME_CLASS(CClientView), CSize(0, nHeight / FRACTION * 3), pContext);
m_wndSplitterRight.CreateView(1, 0, RUNTIME_CLASS(CMessageView), CSize(0, 0), pContext);

// mentions : the function must return TRUE.
return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}