From 553a04cdd1d642019c32011b5af691bc2bc91e9c Mon Sep 17 00:00:00 2001 From: Tu Dinh Date: Sun, 30 May 2021 22:05:14 +0200 Subject: [PATCH] center setting window --- VietTypeATL/SettingsDialog.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/VietTypeATL/SettingsDialog.cpp b/VietTypeATL/SettingsDialog.cpp index 3cfb78d..b4d9873 100644 --- a/VietTypeATL/SettingsDialog.cpp +++ b/VietTypeATL/SettingsDialog.cpp @@ -32,16 +32,29 @@ INT_PTR CALLBACK SettingsDialog::SettingsDialogProc(_In_ HWND hwndDlg, _In_ UINT instance = reinterpret_cast(lParam); assert(instance); + MONITORINFO minfo{ sizeof(minfo) }; + RECT dlgrect; + if (GetMonitorInfo(MonitorFromWindow(hwndDlg, MONITOR_DEFAULTTONEAREST), &minfo) && GetWindowRect(hwndDlg, &dlgrect)) { + LONG wx = minfo.rcWork.left / 2 + minfo.rcWork.right / 2 + dlgrect.left / 2 - dlgrect.right / 2; + LONG wy = minfo.rcWork.top / 2 + minfo.rcWork.bottom / 2 + dlgrect.top / 2 - dlgrect.bottom / 2; + SetWindowPos( + hwndDlg, + HWND_TOP, + std::clamp(wx, 0l, std::max(0l, minfo.rcWork.right - minfo.rcWork.left - dlgrect.right + dlgrect.left)), + std::clamp(wy, 0l, std::max(0l, minfo.rcWork.bottom - minfo.rcWork.top - dlgrect.bottom + dlgrect.top)), + 0, + 0, + SWP_NOSIZE | SWP_NOZORDER); + } + CheckDlgButton(hwndDlg, IDC_SETTINGS_DEFAULT_ENABLED, instance->Property() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_SETTINGS_OA_UY, instance->Property() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_SETTINGS_ACCEPT_DD, instance->Property() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_SETTINGS_BACKSPACE_INVALID, instance->Property() ? BST_CHECKED : BST_UNCHECKED); return TRUE; - } - switch (uMsg) { - case WM_COMMAND: + } else if (uMsg == WM_COMMAND) { assert(instance); switch (LOWORD(wParam)) { case IDOK: @@ -58,7 +71,6 @@ INT_PTR CALLBACK SettingsDialog::SettingsDialogProc(_In_ HWND hwndDlg, _In_ UINT EndDialog(hwndDlg, IDCANCEL); return TRUE; } - break; } return FALSE;