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



Comments

  • htBEYe NS eY Djn KlNS ww

    Posted by BMfhvXRJMJ on 11/01/2012 09:11am

    buy tramadol no prescription overnight buy-tramadol.info - tramadol high alcohol

    Reply
  • Great Work Around!!!

    Posted by Legacy on 03/20/2003 12:00am

    Originally posted by: Jerry G. Scherer

    Just wanted to thank you for your example. I have been working on a method to bypass the right click popup menu in the CFileDialog. This has been a problem in restricted netwrok configurations. If the popup menu is allowed to become active, the operator has the ability to delete, reanme or cause other havoc in the system.

    Thanks Again, it is a great example of the windows dialog we have all come to know and use...

    Reply
  • Some problems in showing Files in List Control

    Posted by Legacy on 01/01/2002 12:00am

    Originally posted by: antu

    It doesn't shows the files in the desktop folders. and when select Network Neighbour hood it doesn't shows the network structure. Please tell how to implement these things.
    
    

    Thanx in advance,
    Antu

    Reply
  • Some missing bits

    Posted by Legacy on 09/05/2001 12:00am

    Originally posted by: Jonathan

    I found some features are not implemented compare with standard file dialog box:
    1) Multiple file selection
    2) Right mouse click
    3) File deletion
    4) New item will never show when the dialog box is still opening
    5) Refreshing the list(F5)
    Implementing those features will sure make the program even better.

    Reply
  • Great idea, but a few problems

    Posted by Legacy on 07/12/2001 12:00am

    Originally posted by: JohnE

    Xiaolong has definitely done a fantastic job at replacing the standard File Open dialog and for all the reasons he states - I've long thought of writing something similar because of the restrictions with the standard Microsoft offering (inability to use with Property Pages & Form Views etc).

    Two small criticisms though. Firstly there are very few comments, over and above the standard ones generated by Visual C++. This is a great shame because some parts of the program are heavily recursive and aren't very easy to follow. Second problem is that whenever any change is made to the List Control view (such as displaying a new directory) every single drive on your system gets re-read for no apparent reason. It's quite easy to stop this once you understand the program but it can be very irritating at first. Apart from those minor points though, brilliant!

    Reply
  • Very Good Job and Effort!

    Posted by Legacy on 01/05/2001 12:00am

    Originally posted by: Tuong Dam

    This is a very good example for learning MFC and building my own classes that is similar to Microsoft's.

    Reply
  • What wrong with the systematic information?

    Posted by Legacy on 10/25/2000 12:00am

    Originally posted by: He Yingxia


    Some of the systematic information of files,e.g. icon, size, cannot be showed in NT4.0.Who can tell me how to do with it?

    Reply
  • Nice code... but it still needs some fixing.

    Posted by Legacy on 08/16/2000 12:00am

    Originally posted by: Zeb

    Hi,

    Your code is pretty usefull. I fand some bugs that I fixed in order to use it in a small application. All of them were in CFileDlg.

    In OnInitDialog(), you have to use ScreenToClient() with the different RCs you fetch with GetWindowRect(). Otherwise if you have a new dialog , everything will displaced.

    In Traverse(), do not forget to initialize
    LPCITEMIDLIST pidlInsideCopy = NULL;
    LPITEMIDLIST pidlInside = NULL;
    and to test their value:
    if (pidlInside == NULL)
    break ;
    Sometimes, the test:
    if (!SUCCEEDED(pEnumIDList->Next(1, &pidlInside,&lFetched)) || lFetched != 1)
    break;
    works, even if pidlInside is set to NULL, and it makes the application crash due to: CopyItemID(pidlInside).

    A next step in this work could be to modify Traverse() so that it does not test the floppy (pFolder->GetAttributesOf(1, &pidlInsideCopy, &ul);) each time you change of directory.

    Many thanks

    Reply
  • Great code, but has some problems on other languages

    Posted by Legacy on 04/23/1999 12:00am

    Originally posted by: Rosa Bernardez

    To make a more reusable class code, it would be a good idea
    to put all strings in the resources, in other languages
    there is no "Desktop" or "Folder" --"Escritorio" and
    "Carpeta" in Spanish.
    But your class has been very useful for me,
    I just working on a file selection class on a Wizard.
    Thanks.

    Reply
  • It could be better

    Posted by Legacy on 04/21/1999 12:00am

    Originally posted by: Joseph

    Definitly needs improvement. Especially the fake combobox. For one the correct icons are not displayed. Also it would be easier to use a ComboBoxEx control. The correct icons are also not displayed in the report view either. It would be better to use the system imagelist. It would also be better to use GetLogicalDriveStrings() to get all the available drives rather trying to switch to each one. Like I said need improvement.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds