FILE: Directory Picker Sample Using Modified CFileDialogID: Q105497
|
The default implementation of CFileDialog allows the user to select a
specific file from any drive/directory on the computer. It is possible
to derive a class from CFileDialog, creating a new class that allows
the user to select only a directory. In addition to deriving a new
class, this approach also requires that a custom template be used in
conjunction with the new dialog box. The Directory Picker (DIRPK)
sample implements this functionality.
The following file is available for download from the Microsoft Software
Library:
~ Dirpk.exeFor more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online ServicesDIRPK.EXE was archived as a self-extracting file using the PKware file- compression utility. The archived file contains subdirectories, and therefore, the -d switch needs to be used when decompressing the file to disk.
NOTE: The DIRPK sample was designed using the old style of common file dialogs and will work as intended only on Windows NT 3.51. On Windows 95 and future versions of NT (4.0), if you want to use the old style of common file dialogs, insure that:
m_ofn.Flags &= ~OFN_EXPLORER;
before calling DoModal() on the CFileDialog object. It is likely, however,
that this behavior will change under future versions of Windows and the old
style of common file dialogs will go away. The best way to search for a
folder instead of a specific file is to use the new ::SHBrowseForFolder()
SDK function.
CMyFileDlg cfdlg(FALSE, NULL, NULL, OFN_SHOWHELP | OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT | OFN_ENABLETEMPLATE, NULL,
m_pMainWnd);
cfdlg.m_ofn.hInstance = AfxGetInstanceHandle();
cfdlg.m_ofn.lpTemplateName = MAKEINTRESOURCE(FILEOPENORD);
if (IDOK==cfdlg.DoModal())
...OK processing...
else
...Error processing...
Additional query words: getopenfilename commdlg dirpkr dirpick dirpicker dirpik
Keywords : kbsample kbFileIO kbMFC kbVC
Version : 1.0 1.5 1.51 1.52 2.0
Platform : NT WINDOWS
Issue type :
Last Reviewed: July 13, 1999