【问题标题】:Get scaling factor for secondary screen获取辅助屏幕的缩放因子
【发布时间】:2019-10-18 09:45:25
【问题描述】:

我想获取辅助屏幕的缩放系数。

通过这段代码,我得到了主监视器的正确信息:

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.net screen pinvoke monitor


【解决方案1】:

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

<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

【讨论】:

    猜你喜欢
    • 2013-01-03
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 2020-02-26
    • 2017-11-13
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    相关资源
    最近更新 更多