Solved

CTreeCtrl and CTreeView (Windows Explorer)

Posted on 2009-04-10
7
951 Views
Last Modified: 2013-11-20
I'm using VS 6.0 and MFC and working on creating a FTP client program where my main window has three splitter windows. The first one far to the left uses a TreeView structure and the next two windows over are both ListView structures.  The first splitter window (TreeView) should display only local folders on the C: drive which I have set as the default drive when the program starts up. This same window should allow users to navigate around these folders. The middle splitter window is a ListView will displays the contents (folders and files) of the selected or highlighted folder from the TreeView. The far right splitter window displays the folders and files of the remote FTP site.

My delima is two folds. First how do I implement the TreeView splitter window which allows users to navigate the folders and only folders (no files in this view) to sub folders just like Windows explorer of the C:\ drive. I am populating this TreeView window with some code but it does not work in that it does not show the folders correctly once refreshed.  I have a drop down combo box (not implemented) which allows users to change the selected drive to the other logical available drives on the system.  I have tried writing recursive code for this TreeView window since there are going to be a limited number of recursive calls but my recursive function does not work. I would be happy to paste the preliminary code if it would help. Another words I take the selected node and recurse up the ladder until I reach the top or root node. Once there my function returns and rebuilds the TreeView but only inserting child/parent nodes until we are back to the selected node then at which I want to be able to display all sibling nodes of the one which was selected.

Secondly how do I best inform/call the middle ListView structure once the user selects a folder from the TreeView window ? Can I use custom SendMessage function ? Would this be an elegant method on how to do this ? I had issues compiling when I tried declaring pointers inside the TreeView and ListView pointing to the other class/object.  Hence my reason for suggesting SendMessage function.

I am open to any suggestions and advice. I have also attached my entire project for VS6.0.

Code can be found here
 
http://cid-be6353393c3f8d74.skydrive.live.com/self.aspx/EE/SuperFTPClient-2.zip
 
Then click on the Download link at the top left. 

Open in new window

0
Comment
Question by:VicMe
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 24120039
As to the second part, the MFC Document/View architecure has a standard way to do this. In your CDocument-derived object, call:
    UpdateAllViews
    http://msdn.microsoft.com/en-us/library/eys41xfw(VS.80).aspx
Call this when the selection changes in the tree view. For instance:
    (in CMyTreeView)
    GetDocument()->UpdateAllViews( this, MYHINT_FOLDER_SEL_CHANGED );
Then your List View will get an OnUpdate call. That's where you will check to see if the document has changed and do anything that makes the view look correct.
In similar projects, I made my "document" an internal representation of the disk hierarchy -- in one case a single CStringArray with one item for every folder, in another case, my "document" was a more complex linked-list structure... but the idea is the same.
0
 

Author Comment

by:VicMe
ID: 24120626
Thanks Dan. I got the second part working in my project. Appreciate the reply. Any chance you can take a look at the code posted to find out why the first part does not work ?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 24123931
There is some good example code here:
    populating tree control from text file
    http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_21049150.html
Including links to two projects that include "populating the tree from disk" logic:
    http://www.codeproject.com/treectrl/pathpicker.asp
    http://www.codeproject.com/treectrl/filetree.asp

Be aware that if you use a recursive function, it may take a very long time to populate the entire tree.  Hard disks these days are huge.  Even if you only seek the names of folders, it might take several minutes.  Try the DOS command
   TREE C:\
to see what I mean.  Windows needs to do a FindFirst/FindNext sequence.  The first time you run it, it is rather slow.  The second time, the folders are in cache and it's faster.
0
Independent Software Vendors: 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!

 

Expert Comment

by:eh936
ID: 24124223
Thanks again for the advice. I have decided to abandon the recursion for now partly because II have found the following article/code which I am hoping to port over.

http://www.codeguru.com/cpp/controls/treeview/directorybrowsers/article.php/c717

There is a class called CDirTreeCtrl : public CTreeCtrl that this author has created that does all of the populating that I could possible need within the CTreeView. What I need help in now is how do I go about integrating this class along with the class CSortStringArray which the author appears to have linked to the CDirTreeCtrl ?

I have also taken a look at the following article which the author (different) talks about implementing a CTreeView or CListView using a SDI application also.

http://www.codeguru.com/Cpp/W-D/doc_view/controlviews/article.php/c3269

If you can possible step me through all of this because I am confused about on how to integrate this class. There is a method called GetTreeCtrl(); which is part of the frameworks CTreeView do I use this or do I create or declare my own ? Please keep in mind that my application if you see the project attachment uses a 4 way splitter first view is dereived from CTreeView and the next two are CListView and there is a smaller one also which uses the standard View which the project uses when created.

Thanks again
0
 

Expert Comment

by:eh936
ID: 24124398
Guess what Dan ?

I got it working by using both the links you had posted and the one I had above posted. But what really got me frustrated and very unsure of what I was doing was that the handler  ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemexpanded) implemented in the CDirTreeCtrl class  was not being called by the framework so my TreeCtrl was not being populated at all except for the root node/drive.

I found the work around by reading the below article at CodeGuru and following the suggestions by Microsoft. I guess I was close but really appreciate the links you gave. I downloaded both of them and followed the code closely.

http://www.codeguru.com/forum/archive/index.php/t-243197.html
http://support.microsoft.com/default.aspx?scid=kb;en-us;148533
0
 

Author Closing Comment

by:VicMe
ID: 31569057
Thanks Dan again. Sorry for the wrong user name posting. I forgot that I had two accounts. Cheers
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24124462
Excellent!  
I'm glad that your own research was able to focus in th right places.  Thanks for the grade and the points.  If you run into related problems,  be sure to click the "Ask Related Question" (in this thread) so that I will be notified.
-- Dan
0

Featured Post

Independent Software Vendors: 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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

728 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