如何在视窗10检测辅助显示器的原生屏幕分辨率或缩放系数

问题描述 投票:0回答:2

有两个显示器:继发于从初级左侧。决议:

Primary:   2560*1440 scaling 100%
Secondary: 1920*1200 scaling 150%

在程序启动它EnumDisplayMonitors赋予以下RECTs:

Primary:   0,0,2560,1440
Secondary: -1920,0,-640,800

此外,我试过的代码:

int width, height;
RECT rect = { -1920, 0, -640, 800 };
SystemParametersInfoA(SPI_SETWORKAREA, 0, &rect, 0);
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);

widthheight总是有主监视器的尺寸。

如何检测辅助监视器1920*1200或缩放因子150%的原始分辨率?

这也不行,给人1280*800

BOOL CALLBACK EnumMonitorCallback(HMONITOR hMon, HDC hdc, LPRECT rect, LPARAM param)
{
    MONITORINFOEXA mi;
    mi.cbSize = sizeof(mi);
    GetMonitorInfoA(hMon, &mi);
    HDC dc = CreateDCA("DISPLAY", mi.szDevice, NULL, NULL);
    int width = GetDeviceCaps(dc, HORZRES);
    int height = GetDeviceCaps(dc, VERTRES);
    DeleteDC(dc);
    return TRUE;
}
c++ windows multiple-monitors highdpi
2个回答
2
投票

你的应用程序应该indicate High DPI awareness使操作系统不会尝试说谎的决议试图模仿旧环境。然后DXGI output enumeration gets you所请求的数据。

您可以快速检查这个使用工具在this blog post的底部。我在3840X2160两个监视器,先用175%的缩放和第二与150%。注意下打印“桌面坐标”和“监控DPI”:

#### Output: \\.\DISPLAY4

 * Desktop Coordinates: (0, 0) - (3840, 2160); 3840 x 2160
 * Attached To Desktop: 1
 * Rotation: DXGI_MODE_ROTATION_IDENTITY
 * Monitor: 0x000100B3
 * Physical Monitors: LG ULTRA HD(DisplayPort) (0x00000000)
 * Bits Per Color: 10
 * Color Space: DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
 * Primaries, White Point: R { 0.652, 0.335 }, G { 0.305, 0.637 }, B { 0.148, 0.062 }; { 0.313, 0.329 }
 * Luminance: Min 0.500, Max 270.000, Max Full Frame 270.000
 * Hardware Composition Support: DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN | DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_CURSOR_STRETCHED
 * Monitor DPI, MDT_EFFECTIVE_DPI: 168, 168 ; System DPI 168
 * Monitor DPI, MDT_ANGULAR_DPI: 161, 160
 * Monitor DPI, MDT_RAW_DPI: 162, 161

…

#### Output: \\.\DISPLAY5

 * Desktop Coordinates: (3840, 0) - (7680, 2160); 3840 x 2160
 * Attached To Desktop: 1
 * Rotation: DXGI_MODE_ROTATION_IDENTITY
 * Monitor: 0x000200B1
 * Physical Monitors: LG ULTRA HD(DisplayPort) (0x00000000)
 * Bits Per Color: 10
 * Color Space: DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
 * Primaries, White Point: R { 0.652, 0.335 }, G { 0.305, 0.637 }, B { 0.148, 0.062 }; { 0.313, 0.329 }
 * Luminance: Min 0.500, Max 270.000, Max Full Frame 270.000
 * Hardware Composition Support: DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN | DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_CURSOR_STRETCHED
 * Monitor DPI, MDT_EFFECTIVE_DPI: 144, 144 ; System DPI 168
 * Monitor DPI, MDT_ANGULAR_DPI: 161, 160
 * Monitor DPI, MDT_RAW_DPI: 162, 161

3
投票

GetSystemMetrics呼吁SM_CXSCREENSM_CYSCREEN将返回主显示屏的分辨率。要获得二次显示器分辨率,你需要使用GetDeviceCapsMultiple Display Monitors API

© www.soinside.com 2019 - 2024. All rights reserved.