CView中创建CSplitterWnd
1、创建SDI程序TestViewSplitter
2、添加CLeftView、CRightView两个CView视图
3、打开CTestViewSplitterView头文件,添加定义
CSplitterWnd m_wndSplitter;
4、添加CTestViewSplitterView的WM_CREATE消息函数,添加如下代码:
if(!m_wndSplitter.CreateStatic(this,1,2))
{
return FALSE;
}
BOOL bRet = m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView), CSize(200,100), NULL);
if(!bRet)
{
TRACE0("Failed to create left user pan!");
return FALSE;
}
bRet = m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightView), CSize(100, 100), NULL);
if(!bRet)
{
TRACE0("Failed to create right user pan!");
return FALSE;
}
m_wndSplitter.RecalcLayout();
5、添加CTestViewSplitterView的WM_SIZE消息函数,添加如下代码:
CRect rect;
GetClientRect(&rect);
if(m_wndSplitter.GetSafeHwnd() != NULL)
{
m_wndSplitter.MoveWindow(&rect);
}
6、重新编译,执行程序!