Click here to Skip to main content
15,884,628 members
Articles / Desktop Programming / MFC
Article

DDXFolder & CChooseDirDlg v1.24

Rate me:
Please Sign up or sign in to vote.
4.00/5 (3 votes)
3 Mar 2000 97.6K   1.1K   29   12
A freeware DDX routine for selecting a Directory / Folder.

Introduction

For developers who use MFC, this is a freeware DDX routine which subclasses an edit control to allow you to easily specify a directory (also known as a folder in Windows 95 parlance). When the edit control is correctly setup, it will look like:

The button beside the edit control sports a tooltip when the button is over it and when the button is hit, the following dialog is displayed:

The caption of the dialog can be customized through the DDX routine. Another flag allows the developer to customize the dialog so that it uses the older style common dialog which looks like:

The routine is most useful when you want to specify a folder from somewhere in the user interface such as specifying a directory where a bunch of output files will be placed.

Features
History
Usage
API Reference
Contacting the Author

Features

  • Simple DDX and DDV functions which you can use in your MFC code.
  • Stand alone directory picker class is also included.
  • All the code is fully UNICODE compliant.
  • A simple test app is included.

Usage

To use DDXFolder in your project, simply include ddxfolder.cpp, dlgdir.cpp, the 3 string resources and the dialog resource IDD_FILEOPEN_OLD from the test application in your application. Then #include ddxfolder.h in whichever of your modules requires it and make the appropriate calls. Included is a simple dialog based application which shows how to use it. Basically all you need to do is add to your DoDataExchange function as follows:

void CTestgetfolderDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTestgetfileDlg)
    //}}AFX_DATA_MAP
    DDX_FolderControl(pDX, IDC_FOLDER, 
      m_ctrlGetFolder, dwFlags, _T("Please specify a folder"));
}

History

  • v1.1 (26th November 1997)
    • Used internally by ddxgetfolder() is another class which you may find helpful. Its name is CChooseDirDlg which implements a standalone directory picker dialog which can be used independently of the DDX/DDV functions.
  • v1.2 (16th September 1998)
    • Updated all the documentation to be HTML based as with my other shareware / freeware.
    • Unicode enabled all the code and provision of Unicode build configurations.
    • VC 5 workspace files provided now as standard.
    • Provision of a DDV function.
    • General tidy up of the sample app, including removing all the AppWizard generated comments.
    • All code now compiles cleanly at warning level 4.
    • Replaced all TRACE0 calls with TRACE.
    • Changed name of main function from DDX_GetFolder() to DDX_FolderControl().
    • Module name has been changed from ddxgetfolder to ddxfolder.
    • Sample app now allows read only state of widget to be toggled.
    • Addition of a DDX_FolderValue() function.
    • Changed the IDs of the strings in the resource table which the code uses.
  • v1.21 (17th September 1998)
    • Minor update to some code comments and the online documentation.
  • v1.22 (30th September 1998)
    • Fixed a compiler problem in the .rc file. I was accidentally shipping the wrong resource.h file.
  • 7th February 1999
    • Minor bug fix in choosedirdlg.cpp.
  • v1.23 (3rd April 1999)
    • Fixed another resource compiler problem.
    • Updated the copyright messages.
    • General code tidy up.
  • v1.24 (11th December 1999)
    • Cosmetic item where now a 1 pixel space is included between the edit control and the "..." button.

API Reference

The following functions are provided:

CChooseDirDlg::GetDirectory

BOOL GetDirectory(CString& sDir, CWnd* pWndParent, BOOL bOldStyleDialog, const CString& sTitle);

Return Value:

TRUE if the applet was successfully displayed otherwise FALSE.

Parameters:

  • sDir -- Used to set the initial directory and upon return contains the newly selected directory.
  • pWndParent -- The parent window to use.
  • bOldStyleDialog -- Allows you to use the older pre Windows 4 style dialog.
  • sTitle -- The title to use on the dialog.

Remarks:

Internally this function is called when you click on the "..." button on the UI. You are free to use this independently of the DDX / DDV code to call up a directory picker dialog in your own code.

DDX_FolderControl

void DDX_FolderControl(CDataExchange* pDX, int nIDC, CGetFolderControl& rCGetFolderControl, DWORD dwFlags, const CString& sDialogTitle);

Parameters:

  • pDX -- The usual CDataExchange object which will be passed into your DoDataExchange function.
  • nIDC -- The dialog ID of the edit control to subclass.
  • rCGetFolderControl -- Will contain upon return the window control which manages the compound edit and button controls.
  • dwFlags -- A combination of the bit values to customize the display of the dialog. See ddxgetfolder.h for all the allowable values.
  • sDialogTitle -- The caption to use for the directory picker dialog.

Remarks:

Associates an existing edit control with dialog ID nIDC to a compound directory picker control. Normally you would put calls to this function in your dialog class' DoDataExchange member function.

DDX_FolderValue

void DDX_FolderControl(CDataExchange* pDX, CGetFolderControl& rCGetFolderControl, CString& sFolder);

Parameters:

  • pDX -- The usual CDataExchange object which will be passed into your DoDataExchange function.
  • rCGetFolderControl -- The folder control to get or set the directory for.
  • sFolder -- The actual folder to get or set into the control depending on the direction of data exchange occurring.

Remarks:

Associates an existing edit control with dialog ID nIDC to a compound directory picker control. Normally you would put calls to this function in your dialog class' DoDataExchange member function.

DDV_FolderControl

void DDV_FolderControl(CDataExchange* pDX, CGetFolderControl& rCGetFolderControl, DWORD dwFlags);

Parameters:

  • pDX -- The usual CDataExchange object which will be passed into your DoDataExchange function.
  • rCGetFolderControl -- The folder control to get or set the directory for.
  • dwFlags -- The flags to use to perform validation. Currently only GFLDR_FOLDER_MUST_EXIST is supported which requires you to enter a valid directory / folder. Normally you would use this flag except in the case where creating the directory may be required such as in an install program.

Remarks:

Associates an existing edit control with dialog ID nIDC to a compound directory picker control. Normally you would put calls to this function in your dialog class' DoDataExchange member function.

Contacting the Author

PJ Naughter

Email: pjn@indigo.ie

Web: http://www.naughter.com

11th December 1999

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow to add a "make a new folder" button Pin
xpmule7-Mar-13 5:11
xpmule7-Mar-13 5:11 
GeneralRoutine crashes program if the edit control is subclassed to a customized CEdit Class. Pin
Michael Cowan13-Mar-02 22:28
Michael Cowan13-Mar-02 22:28 
QuestionHow to reset the current directory? Pin
Masoud Samimi27-Nov-00 10:53
Masoud Samimi27-Nov-00 10:53 
AnswerRe: How to reset the current directory? Pin
Masoud Samimi3-Dec-00 10:31
Masoud Samimi3-Dec-00 10:31 
GeneralWarning in CTestgetfolderDlg::OnRequirevalid() function Pin
PyrosBrother11-Jul-00 0:59
PyrosBrother11-Jul-00 0:59 
GeneralRe: Warning in CTestgetfolderDlg::OnRequirevalid() function Pin
pjnaughter11-Jul-00 12:04
pjnaughter11-Jul-00 12:04 
GeneralImprovements in AddEditButton function Pin
PyrosBrother11-Jul-00 0:51
PyrosBrother11-Jul-00 0:51 
GeneralRe: Improvements in AddEditButton function Pin
pjnaughter11-Jul-00 12:01
pjnaughter11-Jul-00 12:01 
GeneralLittle bug with shortcut Pin
PyrosBrother11-Jul-00 0:23
PyrosBrother11-Jul-00 0:23 
GeneralRe: Little bug with shortcut Pin
pjnaughter11-Jul-00 11:59
pjnaughter11-Jul-00 11:59 
GeneralNice, but small improvent... Pin
George29-Jun-00 4:44
George29-Jun-00 4:44 
GeneralRe: Nice, but small improvent... Pin
pjnaughter29-Jun-00 10:42
pjnaughter29-Jun-00 10:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.