具有两个监视器:从主监视器到左侧的辅助监视器。解决方法:
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;
}
答案 0 :(得分:3)
GetSystemMetrics
调用closeNavbar()
或relativeLayout {
val image : ImageView = imageView(R.mipmap.ic_launcher).lparams {
gravity = left
padding = dip(8)
}
val u_name: TextView=textView {
textSize = 20F
text = "user name"
}.lparams { margin = dip(5)
below(image)
}
}
将返回主显示的分辨率。要获得辅助显示器的分辨率,您需要使用GetDeviceCaps
或Multiple Display Monitors API。
答案 1 :(得分: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
答案 2 :(得分:0)
使用GetScaleFactorForMonitor函数获得比例因子。