CFileDialog Clone

Environment: The code for this article is specific to Visual C++ 6

While we have many code that make dialogs different from the CFileDialog, I am trying to make a dialog that is as close to the CFileDialog as possible. Why reinvent the wheel? There are two reasons.

First reason: Microsoft does not provide a template name nor a resource ID of the CFileDialog. So the CFileDialog can only DoModal(). We will have a hard time if we need a file dialog as one page of a property-sheet/wizard.

Second reason: Many programmers may need only a small portion of the functionalities of CFileDialog. They can copy and paste the code from my dialog.

There are many interesting code snipets in the program.

The use of CComboBoxEx (Suggested by Joseph). This simplified the original code. But the program can no longer be built in VC5. If you need a VC5 version, I may e-mail one to you.

How to display in a list control the file icons for all files. One article in this site uses icon index, I used hIcon attribute in the function SHGetFileInfo()

Traverse along a filepath and get needed information on the way.

The code shows how to use OWNERDRAW for CListBoxes. For disabled button images, one needs to draw additional lines to make the picture look right

Drag and drop items in a list control. There is an article in this site on this topic, but the drag image does not show at the exact right position.

My file dialog is still not identical to CFileDialog yet since I cannot afford more time now. I will add the following features when I got time:
1. In CFileDialog, the columns always align to the left. I need to overridr OnHScroll().
2. Only three commands (Select, Rename, Delete) in the popup menu are coded. The rename function is not quite right yet. It cannot distinguish empty entry from no change. Any comments and suggestions are welcome.

Download source - 27 KB

Date Last Updated: April 24, 1999

This article was originally published on April 24th, 1999

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date