Path: blob/master/src/updater/win32_window_util.cpp
7197 views
// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin <[email protected]>1// SPDX-License-Identifier: CC-BY-NC-ND-4.023#include "win32_window_util.h"45void Win32WindowUtil::CenterWindowOnMonitorAtCursorPosition(HWND hwnd)6{7// Get the current cursor position8POINT cursor_pos = {};9GetCursorPos(&cursor_pos);1011// Find the monitor containing the cursor12HMONITOR monitor = MonitorFromPoint(cursor_pos, MONITOR_DEFAULTTONEAREST);1314// Get monitor info (work area excludes taskbar)15MONITORINFO mi = {};16mi.cbSize = sizeof(MONITORINFO);17if (!GetMonitorInfoW(monitor, &mi))18return;1920// Get the window dimensions21RECT window_rect = {};22GetWindowRect(hwnd, &window_rect);23const int window_width = window_rect.right - window_rect.left;24const int window_height = window_rect.bottom - window_rect.top;2526// Calculate centered position within the monitor's work area27const RECT& work_area = mi.rcWork;28const int window_x = work_area.left + (work_area.right - work_area.left - window_width) / 2;29const int window_y = work_area.top + (work_area.bottom - work_area.top - window_height) / 2;3031// Move the window32SetWindowPos(hwnd, nullptr, window_x, window_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);33}343536