1

I would like to use a CFolderPickerDialog instance for the purpose of 'Save As'.

In other words, the user will input the name of a (new) folder, which I can then create.

With the CFileDialog base class, this can be done during construction via the first input argument:

BOOL bOpenFileDialog // TRUE for FileOpen, FALSE for FileSaveAs

How can I go about achieving the same functionality for a CFolderPickerDialog instance?

halfer
  • 19,824
  • 17
  • 99
  • 186
goodvibration
  • 5,980
  • 4
  • 28
  • 61
  • It looks like only the open dialog supports the folder picker mode. From [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx): _`FOS_PICKFOLDERS` Present an Open dialog that offers a choice of folders rather than files._ - As workaround you may use the regular file save dialog and only use the folder portion of the selected file path. – zett42 Aug 17 '17 at 15:37
  • @zett42: Yes, that's exactly what I had in mind after reading the answer posted below. More accurately, just create a folder with the name selected by the user (regardless of whether or not it has an extension). Thanks! – goodvibration Aug 17 '17 at 15:41
  • Yes, it just came to my mind that you can in fact use the full "file" path as the folder path to create. Another suggestion - call `dialog.GetIFileSaveDialog()->SetFileNameLabel(L"&Folder:");` to rename the label of the edit control appropriately. Maybe you even find a way to hide the file extension combo box (`CFileDialog::HideControl()` maybe). – zett42 Aug 17 '17 at 15:54

1 Answers1

2

You can not achieve this with CFolderPickerDialog as per my understanding. Le me explain you this. Base class of CFolderPickerDialog is CFileDialog and bOpenFileDialog the flag which will allow you to launch file dialog as open or save.

Since, CFolderPickerDialog is child class hence microsoft has to provide call to parent (CFileDialog) in constructor. If you open dlgfile.cpp from ..\Microsoft Visual Studio 14.0\VC\atlmfc\src\mfc\ then you will get source code of CFolderPickerDialog class.

Now coming to point, if you observe the constructor of CFolderPickerDialog then you get exact reason why its not possible.

////////////////////////////////////////////////////////////////////////////
// Folder Picker common dialog helper

CFolderPickerDialog::CFolderPickerDialog(LPCTSTR lpszFolder, DWORD dwFlags, CWnd* pParentWnd, DWORD dwSize, BOOL fNonFileSystemFolders) :
    CFileDialog(TRUE, NULL, lpszFolder, dwFlags, NULL, pParentWnd, dwSize, TRUE)
{
    m_bPickFoldersMode = TRUE;
    m_bPickNonFileSysFoldersMode = fNonFileSystemFolders;
}

First flag is always true that indicate unfortunately, CFolderPickerDialog will open in File Open mode only.

Santosh Dhanawade
  • 1,756
  • 14
  • 29
  • 1
    This is not a matter of the parameters supported by the MFC wrapper class `CFolderPickerDialog`. The underlying common item dialog simply does not support the combination of save dialog and folder picker mode. In fact, I even tried to derive my own folder picker dialog from `CFileDialog` that would set the first `CFileDialog` parameter to `FALSE` but this makes the internal call to `IFileDialog::SetOptions()` fail with `E_INVALIDARG`. – zett42 Aug 17 '17 at 15:42
  • Thank you. I guess that I will just use a `CFileDialog` instance configured in 'Save As' mode, and create a folder with the name selected by the user (regardless of whether or not it has an extension). – goodvibration Aug 17 '17 at 15:42
  • @zett42 Thank you for information. I learn this newly. however, I just want to make point that,CFolderPickerDialog will not support save open flag. :) – Santosh Dhanawade Aug 17 '17 at 15:58