Solved

Text in a Tree View

Posted on 1997-04-07
4
262 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 122
Expand LInux Boot partition remotly 3 78
Host to IP 7 73
Looking for a specific application/software 2 91
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

13 Experts available now in Live!

Get 1:1 Help Now