From d360a43a25c1ba05c52550fb17fb4de9c6ef1b1a Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 31 Mar 2021 14:42:50 +0200 Subject: [PATCH] Windows: Add Screen CLass --- Windows/Screen.vb | 22 ++++++++++++++++++++++ Windows/Window.vb | 2 +- Windows/Windows.vbproj | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Windows/Screen.vb diff --git a/Windows/Screen.vb b/Windows/Screen.vb new file mode 100644 index 00000000..565b5d83 --- /dev/null +++ b/Windows/Screen.vb @@ -0,0 +1,22 @@ +Imports System.Drawing +Imports System.Runtime.InteropServices + +Public Class Screen + + Private Shared Function GetDeviceCaps(ByVal hdc As IntPtr, ByVal nIndex As Integer) As Integer + End Function + + Public Enum DeviceCap + VERTRES = 10 + DESKTOPVERTRES = 117 + End Enum + + Public Shared Function GetScalingFactor() As Single + Dim g As Graphics = Graphics.FromHwnd(IntPtr.Zero) + Dim desktop As IntPtr = g.GetHdc() + Dim LogicalScreenHeight As Integer = GetDeviceCaps(desktop, CInt(DeviceCap.VERTRES)) + Dim PhysicalScreenHeight As Integer = GetDeviceCaps(desktop, CInt(DeviceCap.DESKTOPVERTRES)) + Dim ScreenScalingFactor As Single = CSng(PhysicalScreenHeight) / CSng(LogicalScreenHeight) + Return ScreenScalingFactor + End Function +End Class diff --git a/Windows/Window.vb b/Windows/Window.vb index e8f5f1fa..08932317 100644 --- a/Windows/Window.vb +++ b/Windows/Window.vb @@ -319,7 +319,7 @@ Public Class Window Private Function GetRelativeRectangle(ControlRect As NativeMethods.RectangleAPI, WindowRect As NativeMethods.RectangleAPI, Anchor As Anchor) As NativeMethods.RectangleAPI Try - Dim oScreenRect As Rectangle = Screen.PrimaryScreen.Bounds + Dim oScreenRect As Rectangle = System.Windows.Forms.Screen.PrimaryScreen.Bounds Dim oLeft, oBottom, oTop, oRight As Integer _Logger.Debug("Calculating Rectangle for Anchor {0}", Anchor.ToString) diff --git a/Windows/Windows.vbproj b/Windows/Windows.vbproj index 51646f4e..18ac33ac 100644 --- a/Windows/Windows.vbproj +++ b/Windows/Windows.vbproj @@ -85,6 +85,7 @@ +