Skip to content

Commit 95a27d6

Browse files
committed
Merge branch 'dev' into 0.0.0.3
2 parents eae00ae + 77f1116 commit 95a27d6

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/WPFDevelopers.Shared/Controls/ScreenCut/ScreenCut.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,25 @@ public static class ScreenExtensions
3636
{
3737
public static void GetDpi(this Screen screen, DpiType dpiType, out uint dpiX, out uint dpiY)
3838
{
39-
if (!OSVersionHelper.IsWindows8OrLater())
40-
{
41-
dpiX = 96;
42-
dpiY = 96;
39+
dpiX = 96;
40+
dpiY = 96;
41+
if (!CanUsePerMonitorDpi())
4342
return;
44-
}
4543
var pnt = new System.Drawing.Point(screen.Bounds.Left + 1, screen.Bounds.Top + 1);
4644
var mon = MonitorFromPoint(pnt, 2);
4745
GetDpiForMonitor(mon, dpiType, out dpiX, out dpiY);
4846
}
47+
48+
public static bool CanUsePerMonitorDpi()
49+
{
50+
IntPtr hModule = Win32.LoadLibrary("shcore.dll");
51+
if (hModule == IntPtr.Zero)
52+
return false;
53+
IntPtr procAddr = Win32.GetProcAddress(hModule, "GetDpiForMonitor");
54+
Win32.FreeLibrary(hModule);
55+
return procAddr != IntPtr.Zero;
56+
}
57+
4958
[DllImport(Win32.User32)]
5059
private static extern IntPtr MonitorFromPoint([In] System.Drawing.Point pt, [In] uint dwFlags);
5160
[DllImport(Win32.Shcore)]

src/WPFDevelopers.Shared/Core/Helpers/OSVersionHelper.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ private static int GetWindowsBuildNumber()
8787
return 0;
8888
}
8989

90-
public static bool IsWindows8OrLater()
91-
{
92-
return Environment.OSVersion.Version.Major >= 6 &&
93-
Environment.OSVersion.Version.Minor >= 3;
94-
}
95-
9690
public static bool IsWindows10OrLater()
9791
{
9892
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"))

src/WPFDevelopers.Shared/Core/Helpers/Win32.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ public struct RECT
209209
public int Right;
210210
public int Bottom;
211211
}
212+
213+
[DllImport(Kernel32)]
214+
public static extern IntPtr LoadLibrary(string lpFileName);
215+
216+
[DllImport(Kernel32)]
217+
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
218+
219+
[DllImport(Kernel32)]
220+
public static extern bool FreeLibrary(IntPtr hModule);
212221
}
213222

214223
internal class WindowsMessageCodes
558 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)