首页 > 解决方案 > 获取辅助屏幕的缩放因子

问题描述

我想获得辅助屏幕的比例因子。

使用这段代码,我可以获得主监视器的正确信息:

Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal nIndex As Integer) As Integer
Private Declare Function GetDCEx Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hrgnClip As IntPtr, ByVal DeviceContextValues As DeviceContextValues) As IntPtr

Dim desktop As IntPtr  = GetDCEx(0, 0, DeviceContextValues.Window)

Dim scalling As Double = GetDeviceCaps(desktop, 118) / GetDeviceCaps(desktop, 8)

但是我怎样才能获得第二台显示器的相同信息呢?

GetDCEx 函数中有哪些参数?

标签: vb.netscreenpinvokemonitor

解决方案


谢谢它对我的帮助,这是解决方案:

<DllImport("gdi32.dll")>
Public Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As Integer) As Integer
End Function

<DllImport("gdi32.dll", SetLastError:=True, CharSet:=CharSet.Ansi)>
Public Shared Function CreateDC(<MarshalAs(UnmanagedType.LPStr)> lpszDriver As String,
          <MarshalAs(UnmanagedType.LPStr)> lpszDevice As String,
          <MarshalAs(UnmanagedType.LPStr)> lpszOutput As String,
          lpInitData As IntPtr) As IntPtr
End Function

Public Shared Function GetScalleFactor(index As Integer) As Double
    Dim desktop As IntPtr = CreateDC(Screen.AllScreens(index).DeviceName, Nothing, Nothing, IntPtr.Zero)
    Return GetDeviceCaps(desktop, 118) / GetDeviceCaps(desktop, 8)
End Function

推荐阅读