1.在要分割的View中添加OnCreate消息响应函数 ;
2.分割函数:
int
CUserManagerSplitterView::OnCreate(LPCREATESTRUCT lpCreateStruct)
... {
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
if(!m_wndUserSplitter.CreateStatic(this, 1, 2))
...{
return FALSE;
}
BOOL bRet = m_wndUserSplitter.CreateView(0, 0, RUNTIME_CLASS(CUserLeftPanView), CSize(200, 100), NULL);
if(!bRet)
...{
TRACE0("Failed to create left user pan!");
return FALSE;
}
bRet = m_wndUserSplitter.CreateView(0, 1, RUNTIME_CLASS(CUserRightPanView), CSize(100, 100), NULL);
if(!bRet)
...{
TRACE0("Failed to create right user pan!");
return FALSE;
}
m_wndUserSplitter.RecalcLayout();
return 0;
}
... {
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
if(!m_wndUserSplitter.CreateStatic(this, 1, 2))
...{
return FALSE;
}
BOOL bRet = m_wndUserSplitter.CreateView(0, 0, RUNTIME_CLASS(CUserLeftPanView), CSize(200, 100), NULL);
if(!bRet)
...{
TRACE0("Failed to create left user pan!");
return FALSE;
}
bRet = m_wndUserSplitter.CreateView(0, 1, RUNTIME_CLASS(CUserRightPanView), CSize(100, 100), NULL);
if(!bRet)
...{
TRACE0("Failed to create right user pan!");
return FALSE;
}
m_wndUserSplitter.RecalcLayout();
return 0;
}
3.添加OnSize()响应,显示SplitterWnd:
void
CUserManagerSplitterView::OnSize(UINT nType,
int
cx,
int
cy)
... {
CView::OnSize(nType, cx, cy);
if(this->m_hWnd != NULL)
...{
CRect rect;
GetClientRect(&rect);
if(m_wndUserSplitter.GetSafeHwnd() != NULL)
...{
m_wndUserSplitter.MoveWindow(&rect);
}
}
}
... {
CView::OnSize(nType, cx, cy);
if(this->m_hWnd != NULL)
...{
CRect rect;
GetClientRect(&rect);
if(m_wndUserSplitter.GetSafeHwnd() != NULL)
...{
m_wndUserSplitter.MoveWindow(&rect);
}
}
}
3.如果要Left Pan 与 Right Pan 可相互通信,参考以下代码:
//
在CUserLeftPanView 中定义: CUserRightPanView *m_pUserRightPanView;
// 然后在OnCreate后面添加:
CUserLeftPanView * pUserLeftPanView = (CUserLeftPanView * )m_wndSplitter.GetPane( 0 , 0 );
pUserLeftPanView -> m_pRightPanView = (CUserRightPanView * )m_wndSplitter.GetPane( 0 , 1 );
// 然后在OnCreate后面添加:
CUserLeftPanView * pUserLeftPanView = (CUserLeftPanView * )m_wndSplitter.GetPane( 0 , 0 );
pUserLeftPanView -> m_pRightPanView = (CUserRightPanView * )m_wndSplitter.GetPane( 0 , 1 );
4.分割Frame方法一样;