#If vba7 Then
Declare ptrsafe Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MoniteurInfo) As Long
Declare ptrsafe Function MonitorFromPoint Lib "user32.dll" (ByVal x As Long, ByVal y As Long, ByVal dwFlags As Long) As Long
Declare ptrsafe Function MonitorFromRect Lib "user32.dll" (ByRef lprc As RECT, ByVal dwFlags As Long) As Long
Declare ptrsafe Function MonitorFromWindow Lib "user32.dll" (ByVal hwnd As Longptr, ByVal dwFlags As Long) As Long
Declare ptrsafe Function EnumDisplayMonitors Lib "user32.dll" (ByVal hdc As Longptr, ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As Long
Declare ptrsafe Function GetWindowRect Lib "user32" (ByVal hwnd As Longptr, lpRect As RECT) As Long
#Else
Declare Function GetMonitorInfo Lib "user32.dll" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef lpmi As MoniteurInfo) As Long
Declare Function MonitorFromPoint Lib "user32.dll" (ByVal x As Long, ByVal y As Long, ByVal dwFlags As Long) As Long
Declare Function MonitorFromRect Lib "user32.dll" (ByRef lprc As RECT, ByVal dwFlags As Long) As Long
Declare Function MonitorFromWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal dwFlags As Long) As Long
Declare Function EnumDisplayMonitors Lib "user32.dll" (ByVal hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, ByVal dwData As Long) As Long
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
#End If
Const MONITORINFOF_PRIMARY = &H1
Const MONITOR_DEFAULTTONEAREST = &H2
Const CCHDEVICENAME = 32
Type RECT: Left As Long: Top As Long: Right As Long: Bottom As Long: End Type
Type MoniteurInfo
cbSize As Long
rcMonitor As RECT
rcWork As RECT
dwFlags As Long
szDevice As String * CCHDEVICENAME
End Type
Dim A$
Sub EnumEcrans()
A$ = ""
EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ByVal 1&
MsgBox A$
End Sub
Public Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, lprcMonitor As RECT, ByVal dwData As Long) As Long
Dim MI As MoniteurInfo
MI.cbSize = Len(MI)
GetMonitorInfo hMonitor, MI
With MI.rcMonitor
A$ = A$ & "Moniteur Width/Height : " + CStr(.Right - .Left) + "x" + CStr(.Bottom - .Top) & vbLf
End With
''---
With MI.rcWork
A$ = A$ & "Moniteur Width/Height (surface de travail) : " + CStr(.Right - .Left) + "x" + CStr(.Bottom - .Top) & vbLf
End With
MonitorEnumProc = 1
End Function