Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TreeView did not work

Posted on 1998-04-14
9
Medium Priority
?
341 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:nil_dib
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 1600 total points
ID: 1317674
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
 
LVL 4

Author Comment

by:nil_dib
ID: 1317675
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
 
LVL 7

Expert Comment

by:galkin
ID: 1317676
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Author Comment

by:nil_dib
ID: 1317677
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
 
LVL 7

Expert Comment

by:galkin
ID: 1317678
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
 
LVL 4

Author Comment

by:nil_dib
ID: 1317679
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
 
LVL 7

Expert Comment

by:galkin
ID: 1317680
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
 
LVL 4

Author Comment

by:nil_dib
ID: 1317681
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
 
LVL 4

Author Comment

by:nil_dib
ID: 1317682
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question