Reputation: 63
I am working with MFC MDI. I need to create views as follow. My ChildWnd is splitted in 2 parts. They are LeftView which is a CView and RightView which is a CScrollView. The LeftView is splitted in 2 parts, the TreeView and the the FormView. How can I do that?
_________________________________
| | |
| | |
|CTreeView | |
| | |
| | |
| | CScrollView |
|___________| |
| | |
| | |
|CFormView | |
| | |
| | |
----------------------------------
Upvotes: 3
Views: 5812
Reputation: 178
Maybe this helps: http://www.codeproject.com/Articles/6181/Simple-splitter-with-CWnd-derived-panes
With this class you can make several panes arranged either horizontally or vertically.
Upvotes: 0
Reputation: 63
I finally solved this problem. I wrote the solution for anyone who has a similar problem.
In CChildFrame class, declare CSplitterWnd m_SplitterWnd;
In CChildFrame ::OnCreateClient put the following code:
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 is an MFC CView derived class.
In CLeftView declare a member variable CSplitterWnd m_SplitterWnd;
In CLeftView::OnCreate, add the following code:
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 is a CFormView derived class, CPhong View is a CTreeView class.
In CLeftView::OnSize, put the following code
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();
Upvotes: 3