![](/img/trans.png)
[英]How application can detect scaling and monitors layout change on Windows 10
[英]How to detect native screen resolution or scaling factor of the secondary monitor at Windows 10
有兩個顯示器:從主要的左邊是次要的。 決議:
Primary: 2560*1440 scaling 100%
Secondary: 1920*1200 scaling 150%
在程序開始時,它會執行EnumDisplayMonitors
,它提供以下 RECT:
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);
但width
和height
始終具有主顯示器的尺寸。
如何檢測輔助顯示器的原始分辨率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;
}
GetSystemMetrics
調用SM_CXSCREEN
或SM_CYSCREEN
將返回主顯示器的分辨率。 要獲得輔助顯示器的分辨率,您需要使用GetDeviceCaps
或Multiple Display Monitors API 。
您的應用程序應指示高 DPI 意識,以便操作系統不會試圖對試圖模仿舊環境的分辨率撒謊。 然后DXGI 輸出枚舉為您提供請求的數據。
您可以使用本博文底部的工具快速檢查這一點。 我有兩個 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
使用GetScaleFactorForMonitor函數獲取比例因子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.