c++mfccsplitterwnd

MFC: How can we switch from CTreeCtrl to CTreeView easly?


I have an graphics MFC application which historically was developed by using a CTreeCtrl.
I want to add a CSplitterWnd to improve its graphical interface. However, I found that the CTreeCtrl is not compatible with CSplitterWnd. Apparently i must use a CTreeView.

CSplitterWnd m_wndSplitter;
// Runtime error on CreateView
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(myCTreeCtrl),CSize(100,100),pContext)) 

My problem:
If I switch to CTreeView, i must develop a lot of functions (example: SelectItem)

Question:
How can I switch easly from CTreeCtrl to CTreeView ? or can I for example insert a ctreectrl in a CFormview which will be used instead of CtreeView?


Solution

  • The CTreeView class has member function CTreeCtrl& GetTreeCtrl() const. Replace all occurrences of

    SelectItem(foo);
    

    by

    GetTreeCtrl().SelectItem(foo);