@@ -49,7 +49,7 @@ namespace YY::Thunks::internal
49
49
// / 获取真实的系统DPI。
50
50
// / </summary>
51
51
// / <returns></returns>
52
- static UINT __fastcall RealGetDpiForSystemDownlevel () noexcept
52
+ static UINT __fastcall RealGetDpiForSystemDownlevel (HWND _hSystemAwareWnd = nullptr ) noexcept
53
53
{
54
54
static UINT s_uRealSystemDpi = 0 ;
55
55
if (s_uRealSystemDpi)
@@ -58,7 +58,6 @@ namespace YY::Thunks::internal
58
58
UINT _uDpi = GetDpiForSystemDownlevel ();
59
59
if (_uDpi == USER_DEFAULT_SCREEN_DPI && IsProcessDPIAware () == FALSE )
60
60
{
61
- // 早期系统 主屏Dpi始终等于系统Dpi,因为修改主屏Dpi必须注销。
62
61
HMONITOR _hMonitor = MonitorFromWindow (nullptr , MONITOR_DEFAULTTOPRIMARY);
63
62
if (_hMonitor)
64
63
{
@@ -67,7 +66,31 @@ namespace YY::Thunks::internal
67
66
_oDevMode.dmSize = sizeof (_oDevMode);
68
67
if (GetMonitorInfoW (_hMonitor, &_oMonitorInfo) && EnumDisplaySettingsW (_oMonitorInfo.szDevice , ENUM_CURRENT_SETTINGS, &_oDevMode))
69
68
{
70
- _uDpi = _oDevMode.dmPelsHeight * _uDpi / (_oMonitorInfo.rcMonitor .bottom - _oMonitorInfo.rcMonitor .top );
69
+ // MonitorDpi
70
+ _uDpi = _oDevMode.dmPelsHeight * USER_DEFAULT_SCREEN_DPI / (_oMonitorInfo.rcMonitor .bottom - _oMonitorInfo.rcMonitor .top );
71
+
72
+ // [6.3,) 这类系统屏幕Dpi随时可以改变,MonitorDpi并不一定与系统Dpi相同。
73
+ if (internal::GetSystemVersion () >= __WindowsNT6_3)
74
+ {
75
+ _ASSERT (_hSystemAwareWnd);
76
+ if (!_hSystemAwareWnd)
77
+ return _uDpi;
78
+
79
+ #if (YY_Thunks_Target < __WindowsNT6_3)
80
+ auto const LogicalToPhysicalPointForPerMonitorDPI = try_get_LogicalToPhysicalPointForPerMonitorDPI ();
81
+ #endif
82
+ constexpr uint32_t kLogical = USER_DEFAULT_SCREEN_DPI;
83
+ POINT _uPhysical = { kLogical ,kLogical };
84
+ if (!LogicalToPhysicalPointForPerMonitorDPI (_hSystemAwareWnd, &_uPhysical))
85
+ {
86
+ return _uDpi;
87
+ }
88
+
89
+ // LogicalToPhysicalPointForPerMonitorDPI存在以下转换关系:
90
+ // Physical = Logical * MonitorDpi / SystemDpi;
91
+ // 所以:SystemDpi = Logical * MonitorDpi / Physical;
92
+ _uDpi /* SystemDpi*/ = kLogical * _uDpi / _uPhysical.x ;
93
+ }
71
94
}
72
95
}
73
96
}
@@ -412,7 +435,7 @@ namespace YY::Thunks
412
435
}
413
436
else if (_eTargrtPocressDpiAwareness == PROCESS_DPI_AWARENESS::PROCESS_SYSTEM_DPI_AWARE)
414
437
{
415
- return internal::RealGetDpiForSystemDownlevel ();
438
+ return internal::RealGetDpiForSystemDownlevel (_hWnd );
416
439
}
417
440
else
418
441
{
0 commit comments