Mfc 使用CSplitterWnd在CChildFrame中创建多个视图
我正在使用MFC MDI。我需要创建如下视图。我的孩子被分成两部分。它们分别是LeftView(CView)和RightView(CScrollView)。LeftView分为两部分,TreeView和FormView。我该怎么做Mfc 使用CSplitterWnd在CChildFrame中创建多个视图,mfc,Mfc,我正在使用MFC MDI。我需要创建如下视图。我的孩子被分成两部分。它们分别是LeftView(CView)和RightView(CScrollView)。LeftView分为两部分,TreeView和FormView。我该怎么做 _________________________________ | | | | | | |CTreeView |
_________________________________
| | |
| | |
|CTreeView | |
| | |
| | |
| | CScrollView |
|___________| |
| | |
| | |
|CFormView | |
| | |
| | |
----------------------------------
我终于解决了这个问题。我为任何有类似问题的人编写了解决方案
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);
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);
ClaftView是MFC CView派生的类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);
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派生类,cphongView是一个CTreeView类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();
如果你整理你的代码标签,这将是一个很好的答案。你正在将CREATESTRUCT转换为CCreateContext。这不是一个有效的演员阵容。CREATESTRUCT以零开头,这纯粹是运气使然。