Solved

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

Posted on 1998-01-25
1
1,123 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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now