Click here to Skip to main content
15,867,308 members
Articles / Desktop Programming / MFC

DDXFile v1.11 - DDX Filename Selection

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
3 Mar 2000 80.3K   949   27   6
A freeware DDX routine for selecting a filename
For MFC developers, this is a freeware DDX routine that subclasses an edit control to allow to easily specify a filename.

Introduction

For developers who use MFC, this is a freeware DDX routine which subclasses an edit control to allows you to easily specify a filename. When the edit control is correctly set up, it will look like:

Image 1

The button beside the edit control sports a tooltip when the button is over it and when the button is hit, a modified version of the common file open dialog is displayed to allow the user to select a filename as:

Image 2

Both the caption and file extension filter can be customized through the DDX routine. Other flags allow the developer to customize whether overwrites are notified to the user, only existing files allowed and the option to use the old style common file open dialogs which will look like:

Image 3

The routine is most useful when you want to specify a filename from somewhere in the user interface but don't necessarily want to "Open" or "Save" a file. Note that the default button has the text "OK" as opposed to "Save" or "Open" which is what you normally would get with the standard common file dialogs.

Table of Contents

Features

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

Usage

To use DDXFile in your project, simply include ddxfile.cpp and the six string resources from the test application in your application. Then #include ddxfile.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:

C++
void CTestgetfileDlg::DoDataExchange(CDataExchange* pDX)
{
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(CTestgetfileDlg)
   //}}AFX_DATA_MAP
   DDX_FilenameControl(pDX, IDC_FILE, 
     m_ctrlGetFile, dwFlags, _T("Please specify a filename"));
}

History

v1.1 (17th 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 mak files provided now as standard
  • Provision of a DDV function
  • General tidying 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_GetFileControl() to DDX_FilenameControl()
  • Module name has been changed from ddxgetfile to ddxfile
  • Sample app now allows read only state of widget to be toggled
  • Addition of a DDX_FileValue() function
  • Change the IDs of the strings in the resource table which the code uses

v1.11 (11th December 1999)

  • Cosmetic item where now a 1 pixel space is included between the edit control and the "..." button.

API References

The following functions are provided:

DDX_FilenameControl

C++
void DDX_FilenameControl(CDataExchange* pDX, int nIDC, 
CGetFilenameControl& rCGetFilenameControl, DWORD dwFlags, 
const CString& sDialogTitle, const CString& sExtFilter);

Parameters

  • pDX -- The usual CDataExchange object which will be passed into your DoDataExchange function
  • nIDC -- The dialog ID of the edit control to subclass
  • rCGetFilenameControl -- Contains 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 ddxfile.h for all the allowable values
  • sDialogTitle -- The caption to use for the filename picker dialog

Remarks

Associates an existing edit control with dialog ID nIDC to a compound filename picker control. Normally, you would call this function in your dialog class' DoDataExchange() member function.

DDX_FilenameValue

C++
void DDX_FilenameValue(CDataExchange* pDX, 
CGetFilenameControl& rCGetFilenameControl, CString& sFile);

Parameters

  • pDX -- The usual CDataExchange object which will be passed into your DoDataExchange function
  • rCGetFilenameControl -- The folder control to get or set the filename for
  • sFile -- The actual file to get or set into the control, depending on the direction of data exchange occurring

DDV_FilenameControl

C++
void DDV_FilenameControl
(CDataExchange* pDX, CGetFilenameControl& rCGetFilenameControl, DWORD dwFlags);

Parameters

  • pDX -- The usual CDataExchange object which will be passed into your DoDataExchange function
  • rCGetFilenameControl -- The filename control to get or set the filename for
  • dwFlags -- The flags to customize the behavior of the control. The available flags are:
    • GF_OVERWRITEPROMPT - The user will be prompted about overwriting existing file prior to allowing selection.
    • GF_FILEMUSTEXIST - File must exist to be selected.
    • GF_OLD_STYLE_DIALOG - Use the old style file open dialog instead of the style as used in Windows Explorer.

History

  • 11th December, 1999: Initial version

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

 
GeneralFIX: ShowWindow Pin
Michel Wassink20-Nov-05 21:19
Michel Wassink20-Nov-05 21:19 
GeneralRe: FIX: ShowWindow Pin
Michel Wassink21-Nov-05 21:28
Michel Wassink21-Nov-05 21:28 
Generaldefault folder Pin
Michel Wassink13-Aug-03 21:50
Michel Wassink13-Aug-03 21:50 
GeneralRe: default folder Pin
pjnaughter14-Aug-03 3:47
pjnaughter14-Aug-03 3:47 
GeneralFix: Problem when resizing / moving control Pin
12-Dec-00 21:28
suss12-Dec-00 21:28 
GeneralProblem with a ToolTip Pin
Igor Proskuriakov7-Sep-00 0:14
Igor Proskuriakov7-Sep-00 0:14 
Hi,
I have got the following problem.
I have CModifyButton on a dialog and I call this dialog several times (by DoModal()). The thing is when I close dialog, tool tip control also dies, and when I open dialog again, it is not created (because it is created only in constructor), which causes a problem in PreTranslateMessage.
I fixed like this:
BOOL CModifyButton::PreTranslateMessage(MSG* pMsg)
{
// create the tooltip
if (!m_ToolTip.GetSafeHwnd())
{
m_ToolTip.Create(this);
m_ToolTip.Activate(TRUE);
m_ToolTip.AddTool(this, IDS_DDXFILE_TT_MODIFY);
}

Any comments?
Thanks,
Igo

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.