Milewskp
asked on
How to determine Monitor resolution via VBA code
How can I use VBA code to determine the resoltuion of the monitor (eg 1280 x 1024)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
For computers with multiple monitors, which one are the results for? is there a way to get the res of all monitors?
They are for the primary display. I don't have that type of rig but you could try the following code example.
'// Usage
EnumMonitors
'//
'// Module1.bas
'//
Option Explicit
Private Type RECT
rLeft As Long
rTop As Long
rRight As Long
rBottom As Long
End Type
Private Declare Function EnumDisplayMonitors Lib "User32.dll" (ByVal hdc As Long, ByVal lprcClip As Long, ByVal lpfnEnum As Long, ByVal dwData As Long) As Long
Public Function EnumMonitors()
'// Enumerates all display monitors.
EnumDisplayMonitors 0, 0, AddressOf MonitorEnumProc, 0
End Function
Public Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, ByRef lprcMonitor As RECT, ByVal dwData As Long) As Long
Debug.Print lprcMonitor.rRight; lprcMonitor.rBottom
MonitorEnumProc = 1
End Function
ASKER
Hi ,
It looks like GetSystemMetrics() can't give you the resolution of each monitor, but will give the Width and height, in pixels, of the virtual screen (the bounding rectangle of all display monitors). Supported in Windows CE .NET 4.0 and later.
- http://msdn.microsoft.com/en-us/library/aa929225.aspx
It looks like GetSystemMetrics() can't give you the resolution of each monitor, but will give the Width and height, in pixels, of the virtual screen (the bounding rectangle of all display monitors). Supported in Windows CE .NET 4.0 and later.
- http://msdn.microsoft.com/en-us/library/aa929225.aspx
ASKER
Thanks to both of you for your input.
Open in new window