以下是我的代码
我想要的效果是分割为上下两个视图,比例按照上8下2,并且窗口发生变化时还是按照这个比例
//创建
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
{
CRect rect;
GetClientRect(&rect);
int w = rect.Width();
int h = rect.Height();
if (!m_wndSplitter.CreateStatic(this, 2, 1))
return FALSE;
//创建视图并给它分配大小
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CDrawView), CSize(rect.Width(), rect.Height()*8/10), pContext);
m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CInfoView), CSize(rect.Width(), rect.Height()*2/10), pContext);
m_bIsSplitterCreate = TRUE; //创建成功
return TRUE;
}
//重新指定大小
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWndEx::OnSize(nType, cx, cy);
// TODO: 在此处添加消息处理程序代码
CRect rect;
GetClientRect(&rect);
if (m_bIsSplitterCreate)
{
CRect rect; GetWindowRect(&rect);
int nHeight = rect.Height() - 80;
m_wndSplitter.SetRowInfo(0, nHeight, 10);
m_wndSplitter.SetRowInfo(1, 80, 80);
m_wndSplitter.RecalcLayout();
}
}
如下,要注释掉OnCreate里创建视图的代码,因创建的这个视图把分窗给庶住了
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// 创建一个视图以占用框架的工作区
//if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
//{
// LOG_ERROR("未能创建视图窗口");
// return -1;
//}
m_wndSplitter.SetRowInfo(0, nHeight, 10);
->
m_wndSplitter.SetRowInfo(0, nHeight / 2, 10);