Windows: Add Screen CLass

This commit is contained in:
Jonathan Jenne
2021-03-31 14:42:50 +02:00
parent 781a6ae55b
commit d360a43a25
3 changed files with 24 additions and 1 deletions

22
Windows/Screen.vb Normal file
View File

@@ -0,0 +1,22 @@
Imports System.Drawing
Imports System.Runtime.InteropServices
Public Class Screen
<DllImport("gdi32.dll")>
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