aboutsummaryrefslogtreecommitdiff
path: root/c/win.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/win.cpp')
-rw-r--r--c/win.cpp45
1 files changed, 23 insertions, 22 deletions
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 <utility>
+#include <string>
#include <SWI-Prolog.h>
#include <windows.h>
@@ -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<wchar_t*>(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<wchar_t*>(why));
+ EBMessageBox(msg, title, uType);
+}
+
int GetRelativeCursorPos(const HWND hWnd, POINT* const pt) noexcept
{
RECT rc;