Abstract
CFileDialogST
is a re-implementation of the MFC CFileDialog
class made using the SDK APIs. The first valuable feature is the ability to show the new Windows 2000 Open/Save common dialog! Also CFileDialogST
includes a function to easily show the common dialog used to select a folder.
The class supports Unicode and is fully compatible with the original MFC implementation. Constructor and functions have the same name and argument list, so it should be painless to use the new one.
CFileDialogST functions
CFileDialogST(BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL)
Constructs a CFileDialogST
object. Most frequently used parameters can be passed on the argument list.
CFileDialogST(BOOL bOpenFileDialog, LPCTSTR lpszDefExt,
LPCTSTR lpszFileName, DWORD dwFlags,
LPCTSTR lpszFilter, CWnd* pParentWnd)
CFileDialogST()
Constructs a CFileDialogST
object. All required parameters must be initialized by hand accessing the m_ofn
and m_bOpenFileDialog
public members.
DoModal()
This function displays the file selection dialog box and allows the user to make a selection. All required fields of the m_ofn
public structure must be filled. This can be done using the class constructor or accessing directly the structure. Also, the public variable m_bOpenFileDialog
must be set to TRUE
to get an open dialog box or to FALSE
to get a save dialog box.
int DoModal()
CString GetPathName() const
This function returns the full path of the selected file.
CString GetPathName() const
CString GetFileName() const
This function returns the filename of the selected file.
CString GetFileName() const
CString GetFileTitle() const
This function returns the title of the selected file.
CString GetFileTitle() const
CString GetFileExt() const
This function returns the extension of the selected file.
CString GetFileExt() const
CString GetFileDir() const
This function returns the directory (without drive) of the selected file.
CString GetFileDir() const
CString GetFileDrive() const
This function returns the drive of the selected file.
CString GetFileDrive() const
POSITION GetStartPosition() const
This function returns the position of the first element of the filename list.
POSITION GetStartPosition() const
CString GetNextPathName(POSITION& pos) const
This function returns the full path of the next selected file.
CString GetNextPathName(POSITION& pos) const
int SelectFolder(LPCTSTR lpszTitle = NULL, LPCTSTR lpszStartPath = NULL, UINT ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS, CWnd* pParentWnd = NULL)
This function lets the user to select a folder.
int SelectFolder(LPCTSTR lpszTitle, LPCTSTR lpszStartPath,
UINT ulFlags, CWnd* pParentWnd)
CString GetSelectedFolder() const
This function returns the folder selected by the user with a call to SelectFolder
.
CString GetSelectedFolder() const
Example
The CFileDialogST demo application shows how to open files (even with multiple-selection), to ask for a filename to save and how to browse for a folder.
Want to include CFileDialogST in a DLL ?
CFileDialogST
is ready to be used from inside a DLL. You need to export from your DLL CFileDialogST. Include in your DLL's project, the following files:
- FileDialogST.h
- FileDialogST.cpp
Add to your DLL's project settings, the following defines:
_CMLHTDLL_NOLIB_
_CMLHTDLL_BUILDDLL_
From FileDialogST.h, comment the following line:
#define _FILEDIALOGST_NODLL_
Then, update the various #pragma comment(lib, "???")
according to your DLL produced .lib files.
Remarks
This architecture makes possible to add other features to the class. It would be possible, for example, to add the support for the select-computer command dialog. If someone implements new features, I will be happy to include his code in the next CFileDialogST demo application.