fix bug that shobjidl.h isn't supported well on MinGW
This commit is contained in:
parent
3075eccacf
commit
a120447716
@ -16,6 +16,7 @@
|
|||||||
#define NANA_GUI_FILEBOX_HPP
|
#define NANA_GUI_FILEBOX_HPP
|
||||||
#include <nana/gui/basis.hpp>
|
#include <nana/gui/basis.hpp>
|
||||||
#include <nana/filesystem/filesystem.hpp>
|
#include <nana/filesystem/filesystem.hpp>
|
||||||
|
#include <nana/optional.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
@ -16,7 +16,11 @@
|
|||||||
|
|
||||||
#if defined(NANA_WINDOWS)
|
#if defined(NANA_WINDOWS)
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
# include <Shobjidl.h>
|
# ifndef NANA_MINGW //<Shobjidl.h> isn't supported well on MinGW
|
||||||
|
# include <Shobjidl.h>
|
||||||
|
# else
|
||||||
|
# include <Shlobj.h>
|
||||||
|
# endif
|
||||||
#elif defined(NANA_POSIX)
|
#elif defined(NANA_POSIX)
|
||||||
# include <nana/gui/widgets/label.hpp>
|
# include <nana/gui/widgets/label.hpp>
|
||||||
# include <nana/gui/widgets/button.hpp>
|
# include <nana/gui/widgets/button.hpp>
|
||||||
@ -1221,12 +1225,30 @@ namespace nana
|
|||||||
delete impl_;
|
delete impl_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NANA_MINGW
|
||||||
|
static int CALLBACK browse_folder_callback(HWND hwnd, UINT msg, LPARAM lparam, LPARAM data)
|
||||||
|
{
|
||||||
|
// If the BFFM_INITIALIZED message is received
|
||||||
|
// set the path to the start path.
|
||||||
|
switch (msg)
|
||||||
|
{
|
||||||
|
case BFFM_INITIALIZED:
|
||||||
|
if (data)
|
||||||
|
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; // The function should always return 0.
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::optional<folderbox::path_type> folderbox::show() const
|
std::optional<folderbox::path_type> folderbox::show() const
|
||||||
{
|
{
|
||||||
#ifdef NANA_WINDOWS
|
#ifdef NANA_WINDOWS
|
||||||
std::optional<folderbox::path_type> target;
|
std::optional<folderbox::path_type> target;
|
||||||
|
|
||||||
CoInitialize(NULL);
|
::CoInitialize(nullptr);
|
||||||
|
#ifndef NANA_MINGW
|
||||||
IFileDialog *fd(nullptr);
|
IFileDialog *fd(nullptr);
|
||||||
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fd));
|
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fd));
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
@ -1254,7 +1276,28 @@ namespace nana
|
|||||||
}
|
}
|
||||||
fd->Release();
|
fd->Release();
|
||||||
}
|
}
|
||||||
CoUninitialize();
|
#else
|
||||||
|
BROWSEINFO brw = { 0 };
|
||||||
|
wchar_t display_text[MAX_PATH];
|
||||||
|
brw.hwndOwner = reinterpret_cast<HWND>(API::root(impl_->owner));
|
||||||
|
brw.pszDisplayName = display_text;
|
||||||
|
brw.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
|
||||||
|
brw.lpfn = browse_folder_callback;
|
||||||
|
|
||||||
|
std::wstring init_path = impl_->init_path.wstring();
|
||||||
|
brw.lParam = reinterpret_cast<LPARAM>(init_path.c_str());
|
||||||
|
auto pidl = ::SHBrowseForFolder(&brw);
|
||||||
|
|
||||||
|
if (pidl)
|
||||||
|
{
|
||||||
|
wchar_t folder_path[MAX_PATH];
|
||||||
|
if (FALSE != SHGetPathFromIDList(pidl, folder_path))
|
||||||
|
target = folder_path;
|
||||||
|
|
||||||
|
CoTaskMemFree(pidl);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
::CoUninitialize();
|
||||||
|
|
||||||
return target;
|
return target;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user