Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Text in a Tree View

Posted on 1997-04-07
4
Medium Priority
?
297 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 300 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

824 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