summaryrefslogtreecommitdiff
path: root/ui/IFileDialog_Vista
diff options
context:
space:
mode:
Diffstat (limited to 'ui/IFileDialog_Vista')
-rw-r--r--ui/IFileDialog_Vista/ifile_dialog.cpp18
-rw-r--r--ui/IFileDialog_Vista/ifile_dialog.h12
2 files changed, 22 insertions, 8 deletions
diff --git a/ui/IFileDialog_Vista/ifile_dialog.cpp b/ui/IFileDialog_Vista/ifile_dialog.cpp
index 8c3e694c..565dfa1a 100644
--- a/ui/IFileDialog_Vista/ifile_dialog.cpp
+++ b/ui/IFileDialog_Vista/ifile_dialog.cpp
@@ -19,6 +19,7 @@ namespace
{
bool showFolderPickerImpl(HWND ownerWindow, //throw ComError; return "false" if cancelled by user
const wchar_t* defaultFolder, //optional!
+ const GUID* persistenceGuid, //
std::wstring& selectedFolder)
{
ComPtr<IFileDialog> fileDlg;
@@ -27,6 +28,9 @@ bool showFolderPickerImpl(HWND ownerWindow, //throw ComError; return "false" if
CLSCTX_ALL,
IID_PPV_ARGS(fileDlg.init())));
+ if (persistenceGuid)
+ ZEN_CHECK_COM(fileDlg->SetClientGuid(*persistenceGuid));
+
FILEOPENDIALOGOPTIONS dlgOptions = 0;
ZEN_CHECK_COM(fileDlg->GetOptions(&dlgOptions)); //throw ComError
ZEN_CHECK_COM(fileDlg->SetOptions(dlgOptions | FOS_PICKFOLDERS | FOS_NOVALIDATE | FOS_FORCEFILESYSTEM));
@@ -57,7 +61,7 @@ bool showFolderPickerImpl(HWND ownerWindow, //throw ComError; return "false" if
return true;
}
-const wchar_t* allocString(const std::wstring& msg) //ownership passed
+wchar_t* allocString(const std::wstring& msg) //ownership passed
{
auto tmp = new wchar_t [msg.size() + 1]; //std::bad_alloc ?
::wmemcpy(tmp, msg.c_str(), msg.size() + 1); //include 0-termination
@@ -69,9 +73,10 @@ const wchar_t* allocString(const std::wstring& msg) //ownership passed
void ifile::showFolderPicker(void* ownerWindow,
const wchar_t* defaultFolder,
- const wchar_t*& selectedFolder,
+ const GuidProxy* guid,
+ wchar_t*& selectedFolder,
bool& cancelled,
- const wchar_t*& errorMsg)
+ wchar_t*& errorMsg)
{
selectedFolder = nullptr;
cancelled = false;
@@ -79,8 +84,13 @@ void ifile::showFolderPicker(void* ownerWindow,
try
{
+ static_assert(sizeof(GuidProxy) == sizeof(GUID), "");
+ GUID winGuid = {};
+ if (guid)
+ ::memcpy(&winGuid, guid, sizeof(GUID));
+
std::wstring folderPath;
- if (showFolderPickerImpl(static_cast<HWND>(ownerWindow), defaultFolder, folderPath)) //throw ComError
+ if (showFolderPickerImpl(static_cast<HWND>(ownerWindow), defaultFolder, guid ? &winGuid : nullptr, folderPath)) //throw ComError
selectedFolder = allocString(folderPath);
else
cancelled = true;
diff --git a/ui/IFileDialog_Vista/ifile_dialog.h b/ui/IFileDialog_Vista/ifile_dialog.h
index d0099dda..5b4dc532 100644
--- a/ui/IFileDialog_Vista/ifile_dialog.h
+++ b/ui/IFileDialog_Vista/ifile_dialog.h
@@ -25,12 +25,15 @@ namespace ifile
//COM needs to be initialized before calling any of these functions! CoInitializeEx/CoUninitialize
//Requires Windows Vista and later
+typedef char GuidProxy[16]; //= Windows 128-bit GUID; we don't want to include "Guiddef.h" here!
+
DLL_FUNCTION_DECLARATION
void showFolderPicker(void* ownerWindow, //in; ==HWND
const wchar_t* defaultFolder, //in, optional!
- const wchar_t*& selectedFolder, //out: call freeString() after use!
+ const GuidProxy* guid, //set nullptr by default: Windows stores dialog state (position, x, y coordinates, ect.) associated with the process executable name => use other GUID when needed
+ wchar_t*& selectedFolder, //out: call freeString() after use!
bool& cancelled, //out
- const wchar_t*& errorMsg); //out, optional: call freeString() after use!
+ wchar_t*& errorMsg); //out, optional: call freeString() after use!
DLL_FUNCTION_DECLARATION
void freeString(const wchar_t* str);
@@ -40,9 +43,10 @@ void freeString(const wchar_t* str);
----------*/
typedef bool (*FunType_showFolderPicker)(void* ownerWindow,
const wchar_t* defaultFolder,
- const wchar_t*& selectedFolder,
+ const GuidProxy* guid,
+ wchar_t*& selectedFolder,
bool& cancelled,
- const wchar_t*& errorMsg);
+ wchar_t*& errorMsg);
typedef void (*FunType_freeString)(const wchar_t* str);
/*--------------
bgstack15