CFileDialog Clone | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Apr 24, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.