|
|
|
@ -4,6 +4,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using Avalonia.Platform; |
|
|
|
using Avalonia.Win32.Interop; |
|
|
|
using static Avalonia.Win32.Interop.UnmanagedMethods; |
|
|
|
|
|
|
|
namespace Avalonia.Win32 |
|
|
|
@ -28,9 +29,28 @@ namespace Avalonia.Win32 |
|
|
|
(IntPtr monitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr data) => |
|
|
|
{ |
|
|
|
MONITORINFO monitorInfo = MONITORINFO.Create(); |
|
|
|
if (GetMonitorInfo(monitor,ref monitorInfo)) |
|
|
|
if (GetMonitorInfo(monitor, ref monitorInfo)) |
|
|
|
{ |
|
|
|
GetDpiForMonitor(monitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var x, out _); |
|
|
|
var dpi = 1.0; |
|
|
|
|
|
|
|
var shcore = LoadLibrary("shcore.dll"); |
|
|
|
var method = GetProcAddress(shcore, nameof(GetDpiForMonitor)); |
|
|
|
if (method != IntPtr.Zero) |
|
|
|
{ |
|
|
|
GetDpiForMonitor(monitor, MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out var x, out _); |
|
|
|
dpi = (double)x; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var hdc = GetDC(IntPtr.Zero); |
|
|
|
|
|
|
|
double virtW = GetDeviceCaps(hdc, DEVICECAP.HORZRES); |
|
|
|
double physW = GetDeviceCaps(hdc, DEVICECAP.DESKTOPHORZRES); |
|
|
|
|
|
|
|
dpi = (96d * physW / virtW); |
|
|
|
|
|
|
|
ReleaseDC(IntPtr.Zero, hdc); |
|
|
|
} |
|
|
|
|
|
|
|
RECT bounds = monitorInfo.rcMonitor; |
|
|
|
RECT workingArea = monitorInfo.rcWork; |
|
|
|
@ -40,7 +60,7 @@ namespace Avalonia.Win32 |
|
|
|
new PixelRect(workingArea.left, workingArea.top, workingArea.right - workingArea.left, |
|
|
|
workingArea.bottom - workingArea.top); |
|
|
|
screens[index] = |
|
|
|
new WinScreen((double)x / 96.0d, avaloniaBounds, avaloniaWorkArea, monitorInfo.dwFlags == 1, |
|
|
|
new WinScreen(dpi / 96.0d, avaloniaBounds, avaloniaWorkArea, monitorInfo.dwFlags == 1, |
|
|
|
monitor); |
|
|
|
index++; |
|
|
|
} |
|
|
|
|