TreeView did not work

hi,
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)
        return -1;
#ifdef _MARCOC_OLD
    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 |
                                WS_BORDER |
                                TVS_LINESATROOT |
                                TVS_HASLINES |
//                                TVS_SHOWSELALWAYS |
                                TVS_HASBUTTONS |
                                TVS_DISABLEDRAGDROP,
                                rect, this, ID_TREEVIEW ))
    {
        TRACE( _T("Tree control failed to create!") ) ;
        return -1 ;
    }
#endif
    return 0;
}

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
in wincore.cpp.

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?
LVL 4
nil_dibAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

galkinCommented:
If you have view derived from CTreeView you do not need to create tree control, it is created internally by MFC. you have function GetTreeCtrl that returns reference to treecontrol associated with tree view.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nil_dibAuthor Commented:
Ok,
but I tried also:

CTreeCtrl* m_pTree;
HTREEITEM m_hHitItem;

int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
      m_pTree = &GetTreeCtrl();      
...
}

void CMyView::MyMethod()
{
      m_hHitItem = m_pTree->InsertItem("hallo",TVI_ROOT, TVI_LAST );
      m_pTree->SetRedraw(TRUE);
}

and nothing is shown in MyView. In the debug session "m_hHitItem"
is 0 (InsertItem fails) !!!! So something must be wrong!

any comments?
0
galkinCommented:
Try following

CTreeCtrl& m_Tree;
HTREEITEM m_hHitItem;

int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
m_Tree = GetTreeCtrl();
...
}


void CMyView::MyMethod()
{
m_hHitItem = m_Tree.InsertItem("hallo",TVI_ROOT, TVI_LAST );
m_Tree.SetRedraw(TRUE);
}

0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

nil_dibAuthor Commented:
CTreeCtrl& m_Tree;

in my header produces a compiler error:
C2758 Initialisation must be in construcor

and:

void CMyView::MyMethod()
{
      CTreeCtrl &m_pTree = GetTreeCtrl();
      m_hHitItem = m_pTree.InsertItem("hallo",TVI_ROOT,TVI_LAST );
      m_pTree.SetRedraw(TRUE);
}
behaves like the code above: nothing shown, m_hHitItem = 0

more ideas?
0
galkinCommented:
It is very amaizing. I just created test application using AppWizard and chose CTreeView as view. Then I added menu item to frame menu and cut and pasted you code into menu item handler. It woks fine! and m_hHitItem is NOT NULL
0
nil_dibAuthor Commented:
you made something like this in the MainFrame?

void CMainFrame::OnTest()
{
  CTreeCtrl &m_pTree = ((CTreeView*)(GetActiveView( )))->GetTreeCtrl();
....

and inherits your View class from CTreeView?
0
galkinCommented:
I added message handler to view, but it doesn't matter. I added message handler now to frame class and everything works as well.
0
nil_dibAuthor Commented:
thats crazy,
I did the same ... and it didn't work.
Coulld you mail me your complete code ...
I will increase the points to 400.

mail: jds1@ipa.fhg.de

regards dib
0
nil_dibAuthor Commented:
ok ok I'm an idot...

BOOL COpAnalyser00View::PreCreateWindow(CREATESTRUCT& cs)
{
      return CView::PreCreateWindow(cs);
}
 
instead of

BOOL COpAnalyser00View::PreCreateWindow(CREATESTRUCT& cs)
{
      return CTreeView::PreCreateWindow(cs);
}

thanks a lot
dib



0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.