1、CMainFrame增加成員變數:
CSplitterWnd m_wndSplitter;
CSplitterWnd m_wndSplitter1;
2、映射CMainFrame::OnCreateClient函數:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// 建立一個靜態分欄視窗,分為二行一列
if (m_wndSplitter1.CreateStatic(this, 2, 1) == NULL)
{
return FALSE;
}
// 第一行分割為兩列
if (m_wndSplitter.CreateStatic(&m_wndSplitter1, 1, 2, WS_CHILD|WS_VISIBLE, m_wndSplitter1.IdFromRowCol(0, 0)) == NULL)
{
return FALSE;
}
// 設定第一行View
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CToolBarTestView), CSize(200,200), pContext);
m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CToolBarTestView), CSize(600,200), pContext);
// 設定第二行View
m_wndSplitter1.CreateView(1, 0, RUNTIME_CLASS(CToolBarTestView), CSize(20,20), pContext);
// 設定第一行高度
CRect rect;
GetClientRect(&rect);
m_wndSplitter1.SetRowInfo(0, rect.Height() * 2 / 3, 0);
return TRUE;
}
3、擷取指定的View執行個體:
CToolBarTestView* pTestView = (CToolBarTestView*)this->m_wndSplitter.GetPane(0, 1); // 第一行第二列
if (pTestView)
{
return;
}
4、m_wndSplitter.CreateView可建立自訂的各種View,例如:CTreeView、CListView、CRichEditView等等