Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HWND on windows #91

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions portable-file-dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class file_dialog : public dialog
#if _WIN32
static int CALLBACK bffcallback(HWND hwnd, UINT uMsg, LPARAM, LPARAM pData);
#if PFD_HAS_IFILEDIALOG
std::string select_folder_vista(IFileDialog *ifd, bool force_path);
std::string select_folder_vista(IFileDialog *ifd, bool force_path, HWND hwnd);
#endif

std::wstring m_wtitle;
Expand Down Expand Up @@ -1071,8 +1071,9 @@ inline internal::file_dialog::file_dialog(type in_type,
}
filter_list += '\0';

HWND hwnd = GetActiveWindow();
m_async->start_func([this, in_type, title, default_path, filter_list,
options](int *exit_code) -> std::string
options, hwnd](int *exit_code) -> std::string
{
(void)exit_code;
m_wtitle = internal::str2wstr(title);
Expand All @@ -1098,7 +1099,7 @@ inline internal::file_dialog::file_dialog(type in_type,

// In case CoCreateInstance fails (which it should not), try legacy approach
if (SUCCEEDED(hr))
return select_folder_vista(ifd, options & opt::force_path);
return select_folder_vista(ifd, options & opt::force_path, hwnd);
}
#endif

Expand Down Expand Up @@ -1132,7 +1133,7 @@ inline internal::file_dialog::file_dialog(type in_type,
OPENFILENAMEW ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAMEW);
ofn.hwndOwner = GetActiveWindow();
ofn.hwndOwner = hwnd;

ofn.lpstrFilter = wfilter_list.c_str();

Expand Down Expand Up @@ -1407,7 +1408,7 @@ inline int CALLBACK internal::file_dialog::bffcallback(HWND hwnd, UINT uMsg,
}

#if PFD_HAS_IFILEDIALOG
inline std::string internal::file_dialog::select_folder_vista(IFileDialog *ifd, bool force_path)
inline std::string internal::file_dialog::select_folder_vista(IFileDialog *ifd, bool force_path, HWND hwnd)
{
std::string result;

Expand Down Expand Up @@ -1444,7 +1445,7 @@ inline std::string internal::file_dialog::select_folder_vista(IFileDialog *ifd,
ifd->SetOptions(FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM);
ifd->SetTitle(m_wtitle.c_str());

hr = ifd->Show(GetActiveWindow());
hr = ifd->Show(hwnd);
if (SUCCEEDED(hr))
{
IShellItem* item;
Expand Down Expand Up @@ -1628,13 +1629,14 @@ inline message::message(std::string const &title,
m_mappings[IDRETRY] = button::retry;
m_mappings[IDIGNORE] = button::ignore;

m_async->start_func([text, title, style](int* exit_code) -> std::string
HWND hwnd = GetActiveWindow();
m_async->start_func([text, title, style, hwnd](int* exit_code) -> std::string
{
auto wtext = internal::str2wstr(text);
auto wtitle = internal::str2wstr(title);
// Apply new visual style (required for all Windows versions)
new_style_context ctx;
*exit_code = MessageBoxW(GetActiveWindow(), wtext.c_str(), wtitle.c_str(), style);
*exit_code = MessageBoxW(hwnd, wtext.c_str(), wtitle.c_str(), style);
return "";
});

Expand Down