我正在使用 MFC MDI。我需要创建如下视图。我的 ChildWnd 分为两部分。它们是LeftView(CView)和RightView(CScrollView)。 LeftView 分为两部分:TreeView 和 FormView。我怎样才能做到这一点?
_________________________________
| | |
| | |
|CTreeView | |
| | |
| | |
| | CScrollView |
|___________| |
| | |
| | |
|CFormView | |
| | |
| | |
----------------------------------
我终于解决了这个问题。我为有类似问题的人编写了解决方案。
在CChildFrame类中,声明CSplitterWnd m_SplitterWnd;
-
在 CChildFrame::OnCreateClient 中放入以下代码:
if(!m_SplitterWnd.CreateStatic(this, 1, 2))
{
TRACE("Failed to create splitter window");
return FALSE;
}
pContext->m_pNewViewClass = RUNTIME_CLASS(CLeftView);
m_SplitterWnd.CreateView(0, 0, pContext->m_pNewViewClass, CSize(0, 0), pContext);
m_pLeftView=(CLeftView*)m_SplitterWnd.GetPane(0,0);
CCreateContext context;
context.m_pNewViewClass = pContext->m_pNewViewClass; //save original
pContext->m_pNewViewClass = RUNTIME_CLASS(CRightView);
m_SplitterWnd.CreateView(0, 1, pContext->m_pNewViewClass, CSize(0, 0), pContext);
pContext->m_pNewViewClass = context.m_pNewViewClass; //return to original
m_pRightView=(CRightView*)m_SplitterWnd.GetPane(0,1);
int nWidth=rc.Width();
m_SplitterWnd.SetColumnInfo(0, nWidth*0.25, 50);
m_SplitterWnd.SetColumnInfo(1, nWidth*0.75, 50);
CLeftView 是 MFC CView 派生类。
在CLeftView中声明一个成员变量CSplitterWnd m_SplitterWnd;
-
在 CLeftView::OnCreate 中,添加以下代码:
CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;
if(!m_SplitterWnd.CreateStatic(this, 2, 1, WS_CHILD | WS_VISIBLE, AFX_IDW_PANE_FIRST+8))
{
TRACE("Failed to create splitter window");
return FALSE;
}
pContext->m_pNewViewClass = RUNTIME_CLASS(CPhongView);
m_SplitterWnd.CreateView(0, 0, pContext->m_pNewViewClass, CSize(0, 0), pContext);
m_pPhongView=(CPhongView*)m_SplitterWnd.GetPane(0, 0);
CCreateContext context;
context.m_pNewViewClass = pContext->m_pNewViewClass; //save original
pContext->m_pNewViewClass = RUNTIME_CLASS(CPhongInfo);
m_SplitterWnd.CreateView(1, 0, pContext->m_pNewViewClass, CSize(0, 0), pContext);
pContext->m_pNewViewClass = context.m_pNewViewClass; //return to original
m_pPhongInfo=(CPhongInfo*)m_SplitterWnd.GetPane(1, 0);
CPhongInfo是CFormView的派生类,CPhong View是CTreeView的类。
-
在 CLeftView::OnSize 中,放入以下代码
m_SplitterWnd.MoveWindow(0, 0, cx, cy);
int nRow2 = 227;
int nRow1 = cy - 227;
m_SplitterWnd.SetRowInfo(0, nRow1, 0);
m_SplitterWnd.SetRowInfo(1, nRow2, 0);
m_SplitterWnd.RecalcLayout();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)