Solved

TreeView did not work

Posted on 1998-04-14
9
331 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
  • 5
  • 4
9 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 400 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 67
Folder Comparison 12 52
ORA-01403: no data found 43 82
substring method in java 1 79
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now