Open PowerRename on current active monitor (#14774)

This commit is contained in:
Stefan Markovic 2021-12-02 15:09:33 +01:00 committed by GitHub
parent c95fb78cf4
commit 82ad79dd1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,9 +116,28 @@ void AppWindow::CreateAndShowWindow()
LoadStringW(m_instance, IDS_APP_TITLE, title, ARRAYSIZE(title));
// hardcoded width and height (1200 x 600) - with WinUI 3, it should auto-scale to the content
m_window = CreateWindowW(c_WindowClass, title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 1200, 600, nullptr, nullptr, m_instance, this);
int windowWidth = 1200;
int windowHeight = 600;
m_window = CreateWindowW(c_WindowClass, title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, windowWidth, windowHeight, nullptr, nullptr, m_instance, this);
THROW_LAST_ERROR_IF(!m_window);
POINT cursorPosition{};
if (GetCursorPos(&cursorPosition))
{
HMONITOR hMonitor = MonitorFromPoint(cursorPosition, MONITOR_DEFAULTTOPRIMARY);
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &monitorInfo);
SetWindowPos(m_window,
HWND_TOP,
monitorInfo.rcWork.left + (monitorInfo.rcWork.right - monitorInfo.rcWork.left - windowWidth) / 2,
monitorInfo.rcWork.top + (monitorInfo.rcWork.bottom - monitorInfo.rcWork.top - windowHeight) / 2,
0,
0,
SWP_NOSIZE);
}
ShowWindow(m_window, SW_SHOWNORMAL);
UpdateWindow(m_window);
SetFocus(m_window);