From 00447478cd1d0d64752114df49fee5ee8bdcedbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 2 Sep 2022 23:51:40 +0200 Subject: Add Act. --- c/win32.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'c/win32.cpp') diff --git a/c/win32.cpp b/c/win32.cpp index ce1fc9d..2686f2e 100644 --- a/c/win32.cpp +++ b/c/win32.cpp @@ -8,6 +8,8 @@ #include "win32.h" #include "window.h" +static thread_local const wchar_t* s_action; + std::wstring WideFromNarrow(const std::string_view src, const int cp) { int cchNarrow = src.length()+1; @@ -93,23 +95,30 @@ int EBMessageBox(const std::wstring_view text, const std::wstring_view caption, return MessageBox(hWnd, text.data(), caption.data(), uType); } +void Act(const wchar_t* action) +{ + s_action = action; +} + void ShowException(const wchar_t* const fmt, const wchar_t* const title, const UINT uType) noexcept { + if (!s_action) + s_action = L"performing an unknown action"; try { std::rethrow_exception(std::current_exception()); } catch (const WideException& e) { - std::wstring msg(wcslen(fmt)+wcslen(e.What()), 0); - Swprintf(msg, fmt, e.What()); + std::wstring msg(wcslen(fmt)+wcslen(s_action)+wcslen(e.What()), 0); + Swprintf(msg, fmt, s_action, e.What()); EBMessageBox(msg, title, uType); } catch (const std::exception& e) { std::wstring what = WideFromNarrow(e.what()); - std::wstring msg(wcslen(fmt)+what.length(), 0); - Swprintf(msg, fmt, what.c_str()); + std::wstring msg(wcslen(fmt)+wcslen(s_action)+what.length(), 0); + Swprintf(msg, fmt, s_action, what.c_str()); EBMessageBox(msg, title, uType); } catch (...) { const wchar_t* what = L"an unknown error occurred"; - std::wstring msg(wcslen(fmt)+wcslen(what), 0); - Swprintf(msg, fmt, what); + std::wstring msg(wcslen(fmt)+wcslen(s_action)+wcslen(what), 0); + Swprintf(msg, fmt, s_action, what); EBMessageBox(msg, title, uType); } } -- cgit v1.2.3