0

I would like to get the scaling factor of a secondary screen.

With this piece of code I get the right information for the primary monitor:

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)

But how can I get the same information for the 2nd monitor?

Which parameters in the GetDCEx function?

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
r2b2s
  • 203
  • 1
  • 3
  • 12
  • 1
    [Using SetWindowPos with multiple monitors](https://stackoverflow.com/a/53026765/7444103), at the bottom. Don't skip the DpiAwareness part. – Jimi Oct 18 '19 at 09:51

1 Answers1

0

thanks it's help me this is the solution :

<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
r2b2s
  • 203
  • 1
  • 3
  • 12