1.在要分割的View中添加OnCreate消息响应函数 ;
2.分割函数:
int
CUserManagerSplitterView::OnCreate(LPCREATESTRUCTlpCreateStruct)
... {
if(CView::OnCreate(lpCreateStruct)==-1)
return-1;
if(!m_wndUserSplitter.CreateStatic(this,1,2))
...{
returnFALSE;
}
BOOLbRet=m_wndUserSplitter.CreateView(0,0,RUNTIME_CLASS(CUserLeftPanView),CSize(200,100),NULL);
if(!bRet)
...{
TRACE0("Failedtocreateleftuserpan!");
returnFALSE;
}
bRet=m_wndUserSplitter.CreateView(0,1,RUNTIME_CLASS(CUserRightPanView),CSize(100,100),NULL);
if(!bRet)
...{
TRACE0("Failedtocreaterightuserpan!");
returnFALSE;
}
m_wndUserSplitter.RecalcLayout();
return0;
}
... {
if(CView::OnCreate(lpCreateStruct)==-1)
return-1;
if(!m_wndUserSplitter.CreateStatic(this,1,2))
...{
returnFALSE;
}
BOOLbRet=m_wndUserSplitter.CreateView(0,0,RUNTIME_CLASS(CUserLeftPanView),CSize(200,100),NULL);
if(!bRet)
...{
TRACE0("Failedtocreateleftuserpan!");
returnFALSE;
}
bRet=m_wndUserSplitter.CreateView(0,1,RUNTIME_CLASS(CUserRightPanView),CSize(100,100),NULL);
if(!bRet)
...{
TRACE0("Failedtocreaterightuserpan!");
returnFALSE;
}
m_wndUserSplitter.RecalcLayout();
return0;
}
3.添加OnSize()响应,显示SplitterWnd:
void
CUserManagerSplitterView::OnSize(UINTnType,
int
cx,
int
cy)
... {
CView::OnSize(nType,cx,cy);
if(this->m_hWnd!=NULL)
...{
CRectrect;
GetClientRect(&rect);
if(m_wndUserSplitter.GetSafeHwnd()!=NULL)
...{
m_wndUserSplitter.MoveWindow(&rect);
}
}
}
... {
CView::OnSize(nType,cx,cy);
if(this->m_hWnd!=NULL)
...{
CRectrect;
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方法一样;