try this:
BOOL m_bSplitter = FALSE; // 定义为成员变量,初始化为FALSE int CXXXView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFormView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here if(NULL == m_wndSplitter.GetSafeHwnd()) { CCreateContext cc; memset(&cc, 0, sizeof(CCreateContext)); CRect rc; GetWindowRect(&rc); VERIFY(m_wndSplitter.CreateStatic(this, 1, 2, WS_CHILD | WS_VISIBLE)); cc.m_pNewViewClass = RUNTIME_CLASS(CLeftView); VERIFY(m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(300, rc.Height()), &cc)); cc.m_pNewViewClass = RUNTIME_CLASS(CRightView); VERIFY(m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightView), CSize(0, rc.Height()), &cc)); m_wndSplitter.MoveWindow(0, 0, rc.Width(), rc.Height()); m_bSplitter = TRUE; } return 0; } void CXXXView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); // TODO: Add your message handler code here if(m_bSplitter && m_wndSplitter.GetSafeHwnd()) { m_wndSplitter.MoveWindow(0, 0, cx, cy); } }
本文介绍如何在MFC应用程序中实现一个包含左右两个视图的拆分窗口。通过覆盖OnCreate方法来创建静态拆分窗口,并为每个窗格指定不同的视图类。此外,还介绍了如何在窗口大小改变时调整拆分窗口的尺寸。

被折叠的 条评论
为什么被折叠?



