23 lines
835 B
VB.net
23 lines
835 B
VB.net
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
|