如何使用 CreateWindowEx 创建 window 但忽略 Windows 上的比例设置
How to create a window with CreateWindowEx but ignoring the scale settings on Windows
当我使用 CreateWindowEx 创建 window 时,它将遵循分辨率,但也会使用显示设置中的比例设置。因此,在 1920 x 1080 中,如果我尝试创建 window,当比例为 150% 时,大小实际上是 1200 左右。有没有办法绕过这个限制?如果我只是手动将大小设置为 1920 x 1080,我会得到一个裁剪 window。谢谢
auto activeWindow = GetActiveWindow();
HMONITOR monitor = MonitorFromWindow(activeWindow, MONITOR_DEFAULTTONEAREST);
//
// Get the logical width and height of the monitor
MONITORINFOEX monitorInfoEx;
monitorInfoEx.cbSize = sizeof(monitorInfoEx);
GetMonitorInfo(monitor, &monitorInfoEx);
auto cxLogical = monitorInfoEx.rcMonitor.right - monitorInfoEx.rcMonitor.left;
auto cyLogical = monitorInfoEx.rcMonitor.bottom - monitorInfoEx.rcMonitor.top;
vScreenSize = { cxLogical, cyLogical };
WNDCLASS wc;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.hInstance = GetModuleHandle(nullptr);
wc.lpfnWndProc = olc_WindowEvent;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpszMenuName = nullptr;
wc.hbrBackground = nullptr;
wc.lpszClassName = olcT("Wusik SQ480 Engine");
RegisterClass(&wc);
DWORD dwExStyle = 0;
DWORD dwStyle = WS_VISIBLE | WS_POPUP;
olc::vi2d vTopLeft = vWindowPos;
// Keep client size as requested
RECT rWndRect = { 0, 0, vWindowSize.x, vWindowSize.y };
AdjustWindowRectEx(&rWndRect, dwStyle, FALSE, dwExStyle);
int width = rWndRect.right - rWndRect.left;
int height = rWndRect.bottom - rWndRect.top;
olc_hWnd = CreateWindowEx(dwExStyle, olcT("Wusik SQ480 Engine"), olcT(""), dwStyle,
vTopLeft.x, vTopLeft.y, width, height, NULL, NULL, GetModuleHandle(nullptr), this);
感谢 Remy Lebeau,这就像将以下调用添加到应用程序的主初始化一样简单。现在我总是得到 window 物理分辨率而不是逻辑缩放分辨率。
SetProcessDPIAware();
当我使用 CreateWindowEx 创建 window 时,它将遵循分辨率,但也会使用显示设置中的比例设置。因此,在 1920 x 1080 中,如果我尝试创建 window,当比例为 150% 时,大小实际上是 1200 左右。有没有办法绕过这个限制?如果我只是手动将大小设置为 1920 x 1080,我会得到一个裁剪 window。谢谢
auto activeWindow = GetActiveWindow();
HMONITOR monitor = MonitorFromWindow(activeWindow, MONITOR_DEFAULTTONEAREST);
//
// Get the logical width and height of the monitor
MONITORINFOEX monitorInfoEx;
monitorInfoEx.cbSize = sizeof(monitorInfoEx);
GetMonitorInfo(monitor, &monitorInfoEx);
auto cxLogical = monitorInfoEx.rcMonitor.right - monitorInfoEx.rcMonitor.left;
auto cyLogical = monitorInfoEx.rcMonitor.bottom - monitorInfoEx.rcMonitor.top;
vScreenSize = { cxLogical, cyLogical };
WNDCLASS wc;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.hInstance = GetModuleHandle(nullptr);
wc.lpfnWndProc = olc_WindowEvent;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpszMenuName = nullptr;
wc.hbrBackground = nullptr;
wc.lpszClassName = olcT("Wusik SQ480 Engine");
RegisterClass(&wc);
DWORD dwExStyle = 0;
DWORD dwStyle = WS_VISIBLE | WS_POPUP;
olc::vi2d vTopLeft = vWindowPos;
// Keep client size as requested
RECT rWndRect = { 0, 0, vWindowSize.x, vWindowSize.y };
AdjustWindowRectEx(&rWndRect, dwStyle, FALSE, dwExStyle);
int width = rWndRect.right - rWndRect.left;
int height = rWndRect.bottom - rWndRect.top;
olc_hWnd = CreateWindowEx(dwExStyle, olcT("Wusik SQ480 Engine"), olcT(""), dwStyle,
vTopLeft.x, vTopLeft.y, width, height, NULL, NULL, GetModuleHandle(nullptr), this);
感谢 Remy Lebeau,这就像将以下调用添加到应用程序的主初始化一样简单。现在我总是得到 window 物理分辨率而不是逻辑缩放分辨率。
SetProcessDPIAware();