Virtual Developer Workshop: Containerized Development with Docker

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


  • Great Work Around!!!

    Posted by Legacy on 03/20/2003 08: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...

  • Some problems in showing Files in List Control

    Posted by Legacy on 01/01/2002 08: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,

  • Some missing bits

    Posted by Legacy on 09/05/2001 07: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.

  • Great idea, but a few problems

    Posted by Legacy on 07/12/2001 07: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!

  • Very Good Job and Effort!

    Posted by Legacy on 01/05/2001 08: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.

  • What wrong with the systematic information?

    Posted by Legacy on 10/25/2000 07: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?

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

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

    Originally posted by: Zeb


    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)
    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

  • Great code, but has some problems on other languages

    Posted by Legacy on 04/23/1999 07: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.

  • It could be better

    Posted by Legacy on 04/21/1999 07: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.

  • Bug in CLookInBox::DrawItem

    Posted by Legacy on 04/13/1999 07:00am

    Originally posted by: John M. Drescher

    Thank you very much for this solution..

    I found a bug in the CLookInBox::DrawItem(LPDRAWITEMSTRUCT lp) member function. if lp->itemID is negative ( this is possible see the doc on DRAWITEMSTRUCT structure ) the program crashes, ( very frequently on my dual processor NT Box ) and asserts in CObArray.

    Here is a fix that works:

    Old code:
    UINT id = lp->itemID;
    if ( (int)id >= m_aryItemInfo.GetSize() ) ) return;

    New Code:
    int id = lp->itemID;
    if ( ( id < 0 ) || ( id >= m_aryItemInfo.GetSize() ) return;

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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