TreeView did not work
Posted on 1998-04-14
I try to implement a TreeView, but that did not work!
I bild a View class (CMyView) which inherits from CTreeView.
In the MS MFC samples I found a code to create a TreeCtrl in a TreeView class.
The creation von TreeCtrl is implemented int the "OnCreate" method:
int CObjView::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CTreeView::OnCreate(lpCreateStruct) == -1)
RECT rect ;
rect.top = lpCreateStruct->y ;
rect.left = lpCreateStruct->x ;
rect.bottom = lpCreateStruct->cy ;
rect.right = lpCreateStruct->cx ;
if (!GetTreeCtrl().Create( WS_CHILD | WS_VISIBLE |
// TVS_SHOWSELALWAYS |
rect, this, ID_TREEVIEW ))
TRACE( _T("Tree control failed to create!") ) ;
return -1 ;
I copied that method to CMyView. After that I tried to attach some items on
the tree in other methods. Something like this:
GetTreeCtrl().InsertItem("hello", TVI_ROOT, TVI_LAST );
The result: no TreeCtrl was created in my View.
The reason (I think): The TreeCtrl method "Create" is not called in "OnCreate" because of
_MARCOC_OLD is not defined. If I delete the #ifdef statement the produces an error
I tried the same with the MS MFC sample (OLEView) and it's the same behaviour!!!!!!
With the #ifdef statement the "GetTreeCtrl().Create(..." method is not called, because _MARCOC_OLD
is not defined. Without the statement the programm crashes!!
My question: How to implement a TreeView and attach items to it?