Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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 video discusses moving either the default database or any database to a new volume.

747 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

13 Experts available now in Live!

Get 1:1 Help Now