Solved

Text in a Tree View

Posted on 1997-04-07
4
270 Views
Last Modified: 2013-11-20
I have a program that displays a splitter window (very similar to Windows Explorer) and in the left pane, I have a tree view of a hard disk structure.  What I would like to do is place a value next to each entry in this tree (what will be the space of all files under that directory) in response to a menu choice.  I can get it to display it initally, with the following logic:
*User Selects Auto Mode
*Finds the values for each entry in order from top to bottom
*As it goes, it displays the value by using CTreeCtrl::GetItemRect() to figure out the co-ordinates, and then uses TextOut() to display the text.  
My PROBLEM is that whenever something happens, like clicking on another directory or resizing the window, I loose all the data.  As I figure out the data, I put it into a large array for the sake of keeping it, and I thought I could use the virtual  CView::OnDraw() function to re-display it.  Well, this functions never gets called.  What should I use?  I don't know too much about screen updates as you can see, and I am finding out that I know even less than I thought.  

0
Comment
Question by:eye
  • 2
4 Comments
 

Expert Comment

by:goldsmit
ID: 1300923
You need to call UpdateAllViews() or UpdateView() from within your document class.  This will tell the view that the data has changed and it needs to update itself.  This is the common method for the document to communicate its changes to the view.  You might want to optimize the UpdateView() call by selecting just a portion to update if performance is an issue.  You should look at these functions in the Visual help for more information.
0
 

Author Comment

by:eye
ID: 1300924
for clarification's purposes (I might be a bit repetative here), I am using Microsoft Visual C++ 4.0 with MFC 4.0.  I am trying to display text in the same AREA as the tree view, but not strictly PART of the tree (in other words, the tree control doesn't know about it)
0
 

Accepted Solution

by:
LeoV earned 100 total points
ID: 1300925
You --DO-- have to overwrite OnDraw() function of your tree view. To get it called when user changes something on the screen, you can call InvalidateRect().
0
 

Author Comment

by:eye
ID: 1300926
I could not seem to get InvalidateRect() to work properly for me, so I tried calling the OnDraw function manually, which SEEMS to work.  Very strange though, I put a few message box's in the source as an indication of where in the OnDraw() function the program was, and WITH one of the message boxes in it, the function works properly.  When I take it OUT, I no longer get the correct results.  When the MessageBox() line is commented out, it does NOT display all the information, but it DOES display it correctly when the MessageBox() function is hit.
Here is the entire OnDraw() function:

void CDSView::OnDraw(CDC* pDC)
{
      CDSDoc* pDoc = GetDocument();
      ASSERT_VALID(pDoc);
      
      if(m_bAutoMode == TRUE)
      {
            MessageBox("Start Draw");
            CRect rect;
            HTREEITEM hItem;
            CString strTemp;
            UINT nItems = m_adwAutoMode.GetSize();

            hItem = GetTreeCtrl().GetFirstVisibleItem();
            for(short x = 0; x < nItems; x++)
            {
                  GetTreeCtrl().GetItemRect(hItem,&rect,TRUE);
                  strTemp.Format("%u",m_adwAutoMode.GetAt(x));
                  strTemp = InsertCommas(strTemp);
                  pDC->TextOut( (rect.right + 20),
                        rect.top,strTemp);
                  strTemp.Empty();
                  hItem = GetTreeCtrl().GetNextSiblingItem(hItem);
                  if(hItem == NULL)
                        break;
            }
            
      }


}

This seems to work correctly.  (If this is too hard to read, email me at daniel@ktb.net  and I will send it that way)

HELP!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

806 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