diff options
Diffstat (limited to 'c/common.cpp')
-rw-r--r-- | c/common.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/c/common.cpp b/c/common.cpp index d503133..2259b69 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -57,3 +57,48 @@ 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) +{ + extern HWND g_hWnd; + if (!g_hWnd || nCode < 0 || nCode != HCBT_ACTIVATE) + 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); + } + + return 0; +} + +int EBMessageBox(const TCHAR* const tszText, const TCHAR* const tszCaption, const unsigned uType) +{ + extern HWND g_hWnd; + HHOOK hHook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); + if (!hHook) return 0; + MessageBox(g_hWnd, tszText, tszCaption, uType); + UnhookWindowsHookEx(hHook); + if (!hHook) throw Win32Error(GetLastError()); + return 0; +} + +int EBMessageBoxA(const char* const szText, const char* const szCaption, const unsigned uType) +{ + extern HWND g_hWnd; + HHOOK hHook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); + if (!hHook) return 0; + MessageBoxA(g_hWnd, szText, szCaption, uType); + UnhookWindowsHookEx(hHook); + if (!hHook) throw Win32Error(GetLastError()); + return 0; +} |