aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-31 00:15:31 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-31 00:15:31 +0200
commit7138a921143c801ef42f4190b2242ccce38ff8a1 (patch)
tree7f274019a4a0dd3291f4bde8b96ff2b585ce2adf /c
parent8b9fbccf2090f121a492a1c83378ab033c6f0ea2 (diff)
downloadEpisodeBrowser-7138a921143c801ef42f4190b2242ccce38ff8a1.tar.gz
Move EBMessageBox's CBTProc into lambda.
Diffstat (limited to 'c')
-rw-r--r--c/common.cpp50
1 files changed, 25 insertions, 25 deletions
diff --git a/c/common.cpp b/c/common.cpp
index 614bfeb..77d669c 100644
--- a/c/common.cpp
+++ b/c/common.cpp
@@ -50,7 +50,7 @@ wstring_owner WsoFromSz(const char* const sz, const int iCp)
wchar_t* wsz = new wchar_t[cchWideChar];
if (!MultiByteToWideChar(iCp, 0, sz, cbMultiByte, wsz, cchWideChar)) {
delete wsz;
- throw Win32Error(GetLastError());
+ throw Win32Error();
}
return wsz;
}
@@ -108,34 +108,34 @@ Library::~Library()
FreeLibrary(m_hModule);
}
-/* Move message box to center of main window. */
-static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPARAM lParam) noexcept
-{
- extern HWND g_hWnd;
- if (!g_hWnd || nCode < 0 || nCode != HCBT_ACTIVATE)
- return CallNextHookEx(0, nCode, wParam, lParam);
-
- HWND hWnd = (HWND)wParam;
- long lStyle = GetWindowLong(hWnd, GWL_STYLE);
- if (!(lStyle & WS_POPUP)) return 0;
-
- RECT rcMain, rcMsg;
- GetWindowRect(g_hWnd, &rcMain);
- GetWindowRect(hWnd, &rcMsg);
- SetWindowPos(hWnd, NULL,
- rcMain.left+(rcMain.right-rcMain.left)/2-(rcMsg.right-rcMsg.left)/2,
- rcMain.top+(rcMain.bottom-rcMain.top)/2-(rcMsg.bottom-rcMsg.top)/2,
- -1, -1,
- SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
-
- return 0;
-}
-
/* Show message box owned by and centered in the main window. */
int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption, const unsigned uType)
{
extern HWND g_hWnd;
- HHOOK hHook = require(SetWindowsHookEx(WH_CBT, CBTProc, (HINSTANCE)NULL, GetCurrentThreadId()));
+
+ auto proc = [](const int nCode, const WPARAM wParam, const LPARAM lParam) noexcept
+ -> LRESULT CALLBACK
+ {
+ if (!g_hWnd || nCode < 0 || nCode != HCBT_ACTIVATE)
+ return CallNextHookEx(0, nCode, wParam, lParam);
+
+ HWND hWnd = (HWND)wParam;
+ long lStyle = GetWindowLong(hWnd, GWL_STYLE);
+ if (!(lStyle & WS_POPUP)) return 0;
+
+ RECT rcMain, rcMsg;
+ GetWindowRect(g_hWnd, &rcMain);
+ GetWindowRect(hWnd, &rcMsg);
+ SetWindowPos(hWnd, NULL,
+ rcMain.left+(rcMain.right-rcMain.left)/2-(rcMsg.right-rcMsg.left)/2,
+ rcMain.top+(rcMain.bottom-rcMain.top)/2-(rcMsg.bottom-rcMsg.top)/2,
+ -1, -1,
+ SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
+
+ return 0;
+ };
+
+ HHOOK hHook = require(SetWindowsHookEx(WH_CBT, proc, (HINSTANCE)NULL, GetCurrentThreadId()));
int r = MessageBox(g_hWnd, wszText, wszCaption, uType);
require(UnhookWindowsHookEx(hHook));
return r;