Update file dialog for windows
This commit is contained in:
@@ -5,34 +5,40 @@
|
|||||||
#include <shobjidl.h>
|
#include <shobjidl.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
std::string ShowOpenFileDialog() {
|
class FileDialogWrapper {
|
||||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
public:
|
||||||
|
static std::string ShowOpenFileDialog() {
|
||||||
|
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||||
|
|
||||||
IFileDialog *pfd = NULL;
|
IFileDialog *pfd = NULL;
|
||||||
HRESULT hr =
|
HRESULT hr =
|
||||||
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileDialog,
|
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
|
||||||
reinterpret_cast<void **>(&pfd));
|
IID_IFileDialog, reinterpret_cast<void **>(&pfd));
|
||||||
|
std::string file_path_windows;
|
||||||
if (SUCCEEDED(hr)) {
|
|
||||||
// Show the dialog
|
|
||||||
hr = pfd->Show(NULL);
|
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
IShellItem *psiResult;
|
// Show the dialog
|
||||||
hr = pfd->GetResult(&psiResult);
|
hr = pfd->Show(NULL);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
// Get the file path
|
IShellItem *psiResult;
|
||||||
PWSTR pszFilePath;
|
hr = pfd->GetResult(&psiResult);
|
||||||
psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
|
if (SUCCEEDED(hr)) {
|
||||||
psiResult->Release();
|
// Get the file path
|
||||||
CoTaskMemFree(pszFilePath);
|
PWSTR pszFilePath;
|
||||||
|
psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
|
||||||
|
char str[128];
|
||||||
|
wcstombs(str, pszFilePath, 128);
|
||||||
|
file_path_windows = str;
|
||||||
|
psiResult->Release();
|
||||||
|
CoTaskMemFree(pszFilePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
pfd->Release();
|
||||||
}
|
}
|
||||||
pfd->Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return L""; // Return an empty string if no file was selected or an error
|
return file_path_windows;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user