Dialog for Selecting Directories

Introduction

The CDirDialog class is an extension to MFC that allows selection of a directory with several nice user-interface features.

The class is derived from the MFC CFileDialog class. The code was built and tested with VC6 but should work with recent earlier versions of MFC, and probaly later ones too.

What it Does

The Microsoft recommended way to select a directory (folder) is to use SHBrowseForFolder. This facility is rather primitive for many reasons. For example, there is no way to create or delete a directory, view the files in the directory etc. As CFileDialog (and hence CDirDialog) uses the standard file open dialog you can do these things and more. One thing I really like is that the dialog is resizable under Windows 95/98 so you can expand it to see a lot more files/directories.

Since writing this I have found there is similar code on CodeGuru that provides a directory selection facility using CFileDialog. I think this one is better as it avoids a few problems and bugs and has the following extra features:

  • The file display area shows the contents of the current folder as the user types a full path. (Updated when a backslash or Enter is typed.)
  • Directory name completion means that if the characters type are the first characters of an existing directory then the rest of the directory name is displayed so the user can just press Enter. The extra characters are displayed selected so the user can easily override them if desired.
  • If a directory does not exist the user has the otpion of creating it. This will create all ancestor directories that do not exist.
  • The user has the option of toggling the display of files. By default only directories are displayed but the user can select to display different type of files from the "Display Files of Type" drop down list. (This is unlike the others where the display of files can be turned on or off only under programmer, not user, control.)
  • If files are displayed the user cannot select one.
  • Double-clicking a directory name does not select the directory but simply changes the display to show the contents of the directory. To actually select the directory the user must click the Open button.
  • Helpful error messages that explain why a drive name or path is invalid.

How to Use

To use the class just copy and include the DirDialog.h and DirDialog.cpp files into your project. You also need to link with IMAGEHLP.LIB as the standard Windows IMAGEHLP.DLL is called.

To use the dialog create an object of type CDirDialog and call its DoModal member function. In the same way you would for CFileDialog. The constructor takes 3 parameters: the initial directory, a set of file filters (as is often supplied to the CFileDialog constructor) and a pointer to the dialog's parent window. These parameters are optional and default to the current directory, displaying either all files (*.*) or no files (folders only), and no parent window.

The demo project shows how to use the CDirDialog class. The code for the class is included in the demo project. The demo executable is in the Release directory.

See DirDialog.cpp for more info.

Downloads

Download demo and source code project - 27 Kb


Comments

  • GHD Close To You 2013

    Posted by pykodq519 on 07/16/2013 08:16am

    Le redresseur a un attachement de fil en rotation et trois réglages de température différents pour les différentes caractéristiques et les types de cheveux, où la température maximale est de 230 ° convertisseur de tension globale C.Med pour 120-240V est le redresseur trop parfait pour avoir le voyage, et de le stocker en toute sécurité dans le sac résistant à la chaleur inclus dans luxe design.Elegant redresseurs Paris que vous pouvez à la fois les cheveux lisses et boucle avec. [url=http://ghdpascherferfr.blinkweb.com/]ghd lisseur prix[/url] Quand on sait ghd Norvège peut créer une variété de cheveux de style. Donc, nous voulons tous avoir un tel outil. Pour nous permettre easilycreate boucles et les vagues, ainsi que les cheveux raides parfait. Mais vous savez ce lisseur ghd sont le meilleur choix pour vous. Nous devons choisir lisseur ghd approprié pour vous, plutôt que de suivre le chemin de quelqu'un d'autre de l'acheter. [url=http://bbeatsinorge.cabanova.com/]ghd lisseur pas cher[/url] GHD droit tige conteneur livfullheten et lambeaux de cheveux Farget. Près de la rivière pour s'assurer que la chaleur est répartie uniformément, ne devient jamais Hoy, reduserer La fargebevaringsteknologi unique avec IONTEC décoloration av Fargen en stylisme de 70% * et rend le Fargen obtient appareils de coiffage beaucoup plus glansfull.GHD ne fait pas ditt de cheveux terne et sec. Moi, sur IMot: ils empêchent fuktighetstap de style par y infliger ditt de cheveux satengioner unique! Ces ladde négatif ionène célébrations segment à la chevelure ladde positif ditt et reduserer sec, krusete cheveux et tiltrekker fuktighetspartikler de Lufta et leur envoyer votre le Trenger de cheveux le plus.

    Reply
  • Resizing problem

    Posted by Yenny Suryadi on 10/24/2012 02:49am

    I have tried your CDirDialog class, and it works perfectly, it can open dialog for folder only. My problem is, when I tried to resize the CDirDialog becoming bigger, the edit folder path won't resize according to the dialog width. Why?

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

Top White Papers and Webcasts

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds