Search notes:

Examples for Visual Basic for Application accessing the Windows API: EnumDisplayMonitors

EnumDisplayMonitors calls a callback function for each monitor that is attached to the system.
The following example iterates over all monitors and debug-prints their top-left coordinates and size (width x height).
This example needs the VBA declarations of the Windows API which can be found here.
option explicit

sub main()
    EnumDisplayMonitors 0, 0, addressOf monitorEnumProc, 0
end sub


function monitorEnumProc(byVal hMonitor as long, byVal hdcMonitor as long, byRef rMonitor as RECT, byVal dwData as long) as long
   debug.print "Found monitor with top left = " & rMonitor.left & "," & rMonitor.top & " and size = " & (rMonitor.right-rMonitor.left) & "x" (rMonitor.bottom-rMonitor.top)

 ' Return true so as to continue with the enumeration
   monitorEnumProc = true
end function
Github repository WinAPI-4-VBA, path: /examples/EnumDisplayMonitors.bas

See also

Other examples

Index