Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I get a CFileDialog to allow just a directory selection

Posted on 1998-01-25
1
Medium Priority
?
1,149 Views
Last Modified: 2013-12-03
My App needs the ability to select the destination directory for a bunch of downloaded files but I cannot find a way of getting CFileDialog to allow me to just select a directory for the destination, I have to click on a file in the specified directory before the dialog will let me exit by pressing open, and since the directory will more than likely  not contain a file I can select one. Is it possible to use the CFileDialog for this, if not is there another way of doing it?

Mat
0
Comment
Question by:matth012098
1 Comment
 
LVL 32

Accepted Solution

by:
jhance earned 200 total points
ID: 1410330
From the VC++ Knowledge Base:

The following steps use the DIRPK sample to derive a class from CFileDialog which allows the user to select only a directory:


Derive a class from CFileDialog. See the DIRPK sample for the specific implementation.

Modify the default CFileDialog dialog box template to suit the needs of your dialog box. When modifying a default template, be sure to leave all existing controls there--you can move them around, but they must exist. (COMMDLG.DLL expects certain controls to exist in the template.) Of course, you can add new controls if desired. The default dialog box templates can be found in the \MSVC\SAMPLES\COMMDLG directory in Visual C++ for Windows. In Visual C++ 32-bit edition, the templates are found in \MSVC\INCLUDE. Each template has a .DLG file extension.

Include the modified template in your application's .RC file. Note that the default dialog box templates contain constant identifiers such as cmb1, lst1, stc1, and so forth. These constants are defined in the DLGS.H file, located in the \\MSVC\INCLUDE directory. You must include this file in your application's .RC file as well. Using App Studio, choose Set Includes from the File menu and enter
   #include "dlgs.h" in the Read-Only Symbol Directives edit control.


Add any necessary member functions. See the DIRPK sample for implementation details.

Create an object of your new class and call the DoModal function to bring up the dialog box. Code similar to the following should be used:

Sample Code

   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...

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question