Windows: Add Screen CLass
This commit is contained in:
22
Windows/Screen.vb
Normal file
22
Windows/Screen.vb
Normal 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
|
||||
Reference in New Issue
Block a user