visual-c++mfcmultiple-viewscsplitterwnd

CSplitterWnd with two panes : left pane is CTreeView, Right is CFrameWnd : Not able to set different views in Right pane


I am trying to implement a classic Windows Explorer kind of Application, CpliterWnd has two panes : Left pane is CLeftTreeView : public CTreeView Right pane is CRightPaneFrame: public CFrameWnd , CRightPaneFrame has a member variable m_pCustomView.

CustomView is a class i added to a dialog resource ( edited using Resource editor and Add class wizard)

class CustomView : public CFormView
{

DECLARE_DYNCREATE(CustomView)

public:  // Changed to public so that i can instantiate this view on heap
CustomView();           // protected constructor used by dynamic creation
virtual ~CustomView();
BOOL Create(LPCTSTR A, LPCTSTR B, DWORD C,
    const RECT& D, CWnd* E, UINT F, CCreateContext* G); // To override the protected specifier of CFormView::Create()

MainFrame.cpp has the following entry

if (!m_SplitterWnd.CreateView(0, 0, RUNTIME_CLASS(CLeftTreeView), CSize(125, 100),   pContext) ||  !m_SplitterWnd.CreateView(0, 1, RUNTIME_CLASS(CRightPaneFrame), CSize(100, 100), pContext))    
{
     m_SplitterWnd.DestroyWindow();
     return FALSE;
}

And later on in CRightPaneFrame

BOOL CRightPaneFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
    // TODO: Add your specialized code here and/or call the base class
    m_pCustomView = new CustomView;
    m_pCustomView->Create(NULL,NULL,0L,CFrameWnd::rectDefault,this,VIEW_CUSTOM, pContext);
    SetActiveView(m_pCustomView);
    m_pCustomView->ShowWindow(SW_NORMAL);
    RecalcLayout();
    return true;
}

I don't know what I am doing wrong but the CustomView is not getting loaded in the right pane.

Any suggestions on changing the approach or What is wrong with the current approach ??


Solution

  • You have to put the custom view directly into the splitter windows right side, and not inside a CFrameWnd.

    if (!m_SplitterWnd.CreateView(0, 0, RUNTIME_CLASS(CLeftTreeView), CSize(125, 100), pContext) 
    || !m_SplitterWnd.CreateView(0, 1, RUNTIME_CLASS(CCustomView), CSize(100, 100), pContext))
    
    {
        m_SplitterWnd.DestroyWindow();
        return FALSE;
    }