框架分屏
1 在框架窗口类创建分屏成员变量
CSplitterWnd m_splitter;
2 重载OnCreateClient函数
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
CRect rect;
GetClientRect(&rect);
int iLeft = rect.Width()/3 * 2;
int iRight = rect.Width() - iLeft;
if (m_splitter.CreateStatic(this, 1,2) == NULL)
return FALSE;
m_splitter.CreateView(0,0,RUNTIME_CLASS(CSidView),CSize(iLeft,rect.Height()),pContext);
m_splitter.CreateView(0,1,RUNTIME_CLASS(FormView1),CSize(iRight,rect.Height()),pContext);
m_bSplitterCreate = TRUE;
return TRUE;
}
3 添加窗口大小响应函数
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
if (m_bSplitterCreate)
{
CRect rect;
GetClientRect(&rect);
int iLeft = rect.Width()/3 * 2;
int iRight = rect.Width() - iLeft;
m_splitter.SetColumnInfo(0, iLeft, 10);
m_splitter.SetColumnInfo(1, iRight, 10);
m_splitter.RecalcLayout();
}
}