CTreeCtrl and CTreeView (Windows Explorer)

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
Then click on the Download link at the top left. 

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

As to the second part, the MFC Document/View architecure has a standard way to do this. In your CDocument-derived object, call:
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.
VicMeAuthor Commented:
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 ?
There is some good example code here:
    populating tree control from text file
Including links to two projects that include "populating the tree from disk" logic:

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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.


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.


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
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.

VicMeAuthor Commented:
Thanks Dan again. Sorry for the wrong user name posting. I forgot that I had two accounts. Cheers
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.