From ba0750ff48bcf97ef99602fe27322fa706a93b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 22 Aug 2022 01:05:05 +0200 Subject: Add Buf class. --- c/win.cpp | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'c/win.cpp') diff --git a/c/win.cpp b/c/win.cpp index ea47fb0..c7ce7ec 100644 --- a/c/win.cpp +++ b/c/win.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -7,28 +8,6 @@ #include "win.h" #include "wcharptr.h" -void ShowException(const wchar_t* const fmt, const wchar_t* const title, const UINT uType) noexcept -{ - const wchar_t* what = L"an exception"; - WcharPtr why; - - try { - std::rethrow_exception(std::current_exception()); - } catch (const term_t& t) { - what = L"a Prolog exception"; - try { why = PlString(t); } catch (...) {} - } catch (const Win32Error& e) { - what = L"a Windows error"; - try { why = WcharPtr::Copy(e.What()); } catch (...) {} - } catch (const std::exception& e) { - try { why = WcharPtr::FromNarrow(e.what()); } catch (...) {} - } catch (...) {} - - wchar_t msg[512]; - Swprintf(msg, fmt, what, static_cast(why)); - EBMessageBox(msg, title, uType); -} - void WithNextWindow(void (*proc)(HWND)) { /* WithNextWindow uses a CBT hook to call an arbitrary @@ -103,6 +82,28 @@ int EBMessageBox(const std::wstring_view text, const std::wstring_view caption, return MessageBox(g_hWnd, text.data(), caption.data(), uType); } +void ShowException(const wchar_t* const fmt, const wchar_t* const title, const UINT uType) noexcept +{ + const wchar_t* what = L"an exception"; + WcharPtr why; + + try { + std::rethrow_exception(std::current_exception()); + } catch (const term_t& t) { + what = L"a Prolog exception"; + try { why = PlString(t); } catch (...) {} + } catch (const Win32Error& e) { + what = L"a Windows error"; + try { why = WcharPtr::Copy(e.What()); } catch (...) {} + } catch (const std::exception& e) { + try { why = WcharPtr::FromNarrow(e.what()); } catch (...) {} + } catch (...) {} + + std::wstring msg(wcslen(fmt)+wcslen(what)+wcslen(why), 0); + Swprintf(msg, fmt, what, static_cast(why)); + EBMessageBox(msg, title, uType); +} + int GetRelativeCursorPos(const HWND hWnd, POINT* const pt) noexcept { RECT rc; -- cgit v1.2.3