Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am not a full time programmer, but I've been using MFC in multiple Visual Studio versions for some years while I've been writing the code to make my own tools that I needed to use mostly for my work.

Every time it took little effort, but it worked out gracefully with MFC. Most of the times, I've been using MDI rather than SDI, and I also wrote a couple programs in the dialog based structure as well. These tools helped me a lot and also made my co-workers happy as well.

I don't remember exactly when, but I noticed that Microsoft included the nice looking boilerplate framework which has the CFileView, CClassView, COutputWnd, and CPropertiesWnd classes. It definitely looks nicer and seems to complete the program in a better way. I was hoping to use these additions in my programs as well, but it required a lot more than what I could easily achieve.

My simple user model would be to list up the file names(Titles) interactively in the TreeView instead of having the "Fakexxxx.h" or "Fakexxxx.cpp".

I tried multiple google searches for the answer, but my search was not very successful so far. If someone could give a nice answer on this, that would be fantastic. I would like to provide one example program, HelloWorld, where TreeView shows the file name(s) once the files are open, and it also disappears when the file is closed.

Expected behaviors are ...
1. Add the filename or the title in the TreeView when the new file is open.(implemented in the example code)
2. Remove the item when the file/view/doc is closed.(implemented in the example code)
3. Browse to the corresponding view when the item in the TreeView is selected by LButton double click.
4. Remove the item and the corresponding view/doc when "Remove" is selected from the context menu in the TreeView.

Again, I am not a full time programmer, thus this program is not necessarily for the code example, but to give user model ideas. Please open up the program and try it yourself. I also added the 3 example files for you to try as well.

Visual Studio 2015 is used for this example, but I am pretty sure you would be able to compile the program under different Visual Studio versions.

What I have tried:

I would like to attach the example code/project here, but I don't see the option. As soon as I figure out how to attach the example code, I will attach the entire project.

Default
https://postimg.cc/sGBCVr4D

Revised
https://postimg.cc/9zzhPdH5
Posted
Updated 22-Mar-21 23:36pm
v10
Comments
Rick York 22-Mar-21 21:13pm    
I recommend reading a tutorial on the CTreeView. I've never found a need to use it so I haven't.

1 solution

It is easy enough to get a list of file names from the system using FindFirstFileA function (fileapi.h) - Win32 apps | Microsoft Docs[^] and its associated function. You can then build your tree nodes however you like. When the user clicks a file name you can then pass the details (via a Windows or User level message) to one of the views, which can read and display the content. I have done this in the past although not with MFC.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900