File and Directory Picker Control

Environment: VC6

The classes that come with Visual Studio for picking files and directories work, but they aren't as clean and user friendly as they should be. My FilePickCtrl class is very similar to what Explorer uses for views, but with some slight differences. The following features are supported:

  • Display small or large icons for detected drives
  • Display small or large icons for files and directories
  • Add filemasks to limit display of files
  • Display only directories so the user can only choose a directory
  • Turn on/off the display of the current directory



Click here for a larger image.

Small icons for drives and files, with both files and directories being displayed



Click here for a larger image.

Large icons for drives and files, with both files and directories being displayed



Click here for a larger image.

Small icons for drives and files, with only directories being displayed

To add the control to your program, add FilePickCtrl.cpp and FilePickCtrl.h to your project. Drag FilePickCtrlDemo.rc into Resource Editor, expand the Dialog tree, highlight IDD_FILEPICKCTRL_DIALOG, hold down the Ctrl key, drag the dialog into your program's dialog tree, and close the window for FilePickCtrlDemo.rc. Your project should now have a copy of IDD_FILEPICKCTRL_DIALOG in its Resource Editor.

Downloads

Download source files - 28 Kb


Comments

  • Great Job!!!!!!

    Posted by Legacy on 07/15/2003 12:00am

    Originally posted by: Tom Osejo

    Great Job!!!!!!

    Reply
  • Great job!

    Posted by Legacy on 04/13/2003 12:00am

    Originally posted by: Jean-Marc Molina

    Hi,

    Nice article, I don't really understand people who say that it's useless. I wanted to design and develop my own CFileDialog and voil�, thanks to you :). However It still believe it's better to inherit from CFileDialog and to redesign it, hide buttons, resize...

    Thanks again,
    JM

    Reply
  • Thank you for your Code!

    Posted by Legacy on 02/14/2003 12:00am

    Originally posted by: An ki Cho

    Very Nice Program!!!

    Reply
  • Double click problem

    Posted by Legacy on 10/20/2002 12:00am

    Originally posted by: Julius

    This code is very usefull to me, but I have the following problem:
    the shipped executable file works fine, but when I compile the source code and execute (without any modification), a double click in the files/folders list over an empty area generates a "debug assertion failed" error ...
    Does anyone have an idea on how to fix this ?
    Thanks
    J.


    Reply
  • Need Hellllp. get file timestamp / file properties.

    Posted by Legacy on 09/26/2002 12:00am

    Originally posted by: Din Krop

    Hi,

    Can anyone email me how to get file timestamp or file properties or at least get the latest updated file from directory.
    My email: bahruddina@yahoo.com
    Thanx in advance for ur help.

    Regards,
    Din Krop

    Reply
  • So nice of you.

    Posted by Legacy on 09/04/2002 12:00am

    Originally posted by: Sreeram

    Hi,

    I have struggled a lot to find the solution for this. I asked my colleagues, but anybody hardly knows about it. Now my quest has come to an end. Thank you very much.

    Regards

    Sreeram

    Reply
  • Memory leak (?) and small code change

    Posted by Legacy on 07/10/2002 12:00am

    Originally posted by: Linas

    1. Memory leak (?)
    
    I'm not sure, but I think where is a memory leak. Objects created with new are never deleted.

    I replaced

    void CFilePickCtrl::PopulateFilesCtrl()
    {
    ...
    dirData.next = NULL;
    ...

    with:

    CLocalFileCtrl::CLocalFileCtrl()
    {
    dirData.next = NULL;
    fileData.next = NULL;
    }

    void CFilePickCtrl::PopulateFilesCtrl()
    {
    ...
    // pDirData cleanup
    pDirData = dirData.next;
    while (pDirData != NULL)
    {
    pDirData2 = pDirData->next;
    delete pDirData;
    pDirData = pDirData2;
    }
    dirData.next = NULL;

    // pFileData cleanup
    pFileData = fileData.next;
    while (pFileData != NULL)
    {
    pFileData2 = pFileData->next;
    delete pFileData;
    pFileData = pFileData2;
    }
    fileData.next = NULL;
    ...

    2. And small code change:

    if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && findData.cFileName[0] != '.')
    {
    pDirData->next = new struct FILESCTRL_STRUCT;
    ...
    m_numDirItems++;
    }

    while (1)
    {
    if (!FindNextFile(h, &findData))
    break;
    if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && findData.cFileName[0] != '.')
    {
    pDirData->next = new struct FILESCTRL_STRUCT;
    ...
    m_numDirItems++;
    }
    }

    I replaced with:

    do
    {
    if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && findData.cFileName[0] != '.')
    {
    pDirData->next = new struct FILESCTRL_STRUCT;
    pDirData = pDirData->next;
    ...
    m_numDirItems++;
    }
    } while (FindNextFile(h, &findData));

    The same work with smaller source code.

    Reply
  • Thanks

    Posted by Legacy on 06/17/2002 12:00am

    Originally posted by: A user

    Thanks for saving me quite some work.
    Since the original file open / save dialogs do not work in multithreaded COM environments, I could in just a few hours adapt the dialog to my needs without much thinking.

    To the ingnorants who posted other comments:
    Programming is not always just clicking a few dialogs together.

    A user

    Reply
  • good work

    Posted by Legacy on 06/17/2002 12:00am

    Originally posted by: MC

    True, the API provides similar Dialogs, BUT this is a good example of how you could do it. I had to implement once a real specialized FileChooser and Viewer and i would have been lucky to find an example like this.

    In my opinion are the standard API Dialogs really shit ...

    Alea jacta est

    Reply
  • What's this???

    Posted by Legacy on 06/14/2002 12:00am

    Originally posted by: Eric

    I don't understand why you do that?? Win32 has built in fonctions to do this... And in MFC you have the CFileDialog that do that!!

    Sometimes, I really don't understand people!!

    Eric

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

Top White Papers and Webcasts

  • Is your sales and operations planning helping or hurting your bottom line? Here are 5 useful tips from the experts at Quintiq to guide you to a better S&OP strategy.

  • Intelligent N+X Redundancy, Placement Affinities, & Future Proofing in the Virtualized Data Center Virtualization brought about the ability to simplify business continuity management in IT. Workload portability and data replication capabilities mean that physical infrastructure failures no longer need impact application services, and they can rapidly be recovered even in the event of complete site failure. However, Enterprises and Service Providers face new challenges ensuring they have enough compute …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds