From 2ffbd7fcc178e68e7132d2f8f649d131c5a5d3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 19 Jul 2022 14:49:24 +0200 Subject: Add comments. --- c/common.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'c/common.cpp') diff --git a/c/common.cpp b/c/common.cpp index 494c382..a91836d 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -2,6 +2,8 @@ #include "common.h" +/* Win32Error: Exception for Windows API errors. */ + Win32Error::Win32Error(const DWORD dwErr) : m_dwErr(dwErr) {} Win32Error::~Win32Error() @@ -46,6 +48,8 @@ const TCHAR* Win32Error::twhat() const noexcept #undef M } +/* Library: Wrapper for loading and freeing dynamically linked libraries. */ + Library::Library(const TCHAR* const tszLibrary) { m_hModule = LoadLibrary(tszLibrary); @@ -66,21 +70,22 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR return CallNextHookEx(0, nCode, wParam, lParam); HWND hWnd = (HWND)wParam; - if (long lStyle = GetWindowLong(hWnd, GWL_STYLE)) - if (lStyle & WS_POPUP) { - 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); - } + 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 TCHAR* const tszText, const TCHAR* const tszCaption, const unsigned uType) { extern HWND g_hWnd; -- cgit v1.2.3