Create multiple views in CChildFrame using CSplitterWnd

I work with MFC MDI. I need to create views as follows. My ChildWnd is divided into two parts. This is LeftView, which is a CView, and RightView, which is a CScrollView. LeftView is divided into two parts: TreeView and FormView. How can i do this?

_________________________________
|          |                    |
|          |                    |
|CTreeView  |                   |
|          |                    |
|          |                    |
|          |        CScrollView |
|___________|                   |
|          |                    |
|          |                    |
|CFormView  |                   |
|          |                    |
|          |                    |
----------------------------------
+3
source share
2 answers

I finally solved this problem. I have written a solution for everyone who has a similar problem.

  • In the CChildFrame class, declare CSplitterWnd m_SplitterWnd;

  • In CChildFrame :: OnCreateClient, enter 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 a derived class of the MFC CView.

  • CLeftView declares 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 - 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();
    
+3

Source: https://habr.com/ru/post/1773482/


All Articles