From 049ac77cae90bddbfee33765cc1d79a87c857e55 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 16 Mar 2022 09:08:24 +0100 Subject: [PATCH] Fix unkillable Windows message boxes (Closes #69) When a message box uses the Yes/No or Abort/Retry/Ignore style, it ignores any WM_CLOSE message. We explicitly select a button to ensure the window is closed. --- portable-file-dialogs.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/portable-file-dialogs.h b/portable-file-dialogs.h index 53711ac..1ea9b6e 100644 --- a/portable-file-dialogs.h +++ b/portable-file-dialogs.h @@ -1,7 +1,7 @@ // // Portable File Dialogs // -// Copyright © 2018—2020 Sam Hocevar +// Copyright © 2018–2022 Sam Hocevar // // This library is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -595,7 +595,11 @@ inline bool internal::executor::kill() EnumWindows(&enum_windows_callback, (LPARAM)this); for (auto hwnd : m_windows) if (previous_windows.find(hwnd) == previous_windows.end()) + { SendMessage(hwnd, WM_CLOSE, 0, 0); + // Also send IDNO in case of a Yes/No or Abort/Retry/Ignore messagebox + SendMessage(hwnd, WM_COMMAND, IDNO, 0); + } } #elif __EMSCRIPTEN__ || __NX__ // FIXME: do something