Solved

CTreeCtrl and CTreeView (Windows Explorer)

Posted on 2009-04-10
7
891 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:eh936
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

16 Experts available now in Live!

Get 1:1 Help Now