''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const MONITOR_DEFAULTTONULL As Long = &H0 'If the monitor is not found, return 0
Private Const MONITOR_DEFAULTTOPRIMARY As Long = &H1 'If the monitor is not found, return the primary monitor
Private Const MONITOR_DEFAULTTONEAREST As Long = &H2 'If the monitor is not found, return the nearest monitor
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function MonitorFromRect Lib "user32" _
(rc As RECT, _
ByVal dwFlags As Long) As Long
Private Function GetMonitorByRect(rc As RECT) As Long
'Returns a handle to the display monitor that
'has the largest area of intersection with
'a specified rectangle. This rectangle can be
'a form, or any rectangle inside or outside
'the desktops.
'
'If the rectangle intersects one or more display
'monitor rectangles, the return value is an
'HMONITOR handle to the display monitor that
'has the largest area of intersection with the
'rectangle.
'
'If the window does not intersect a display
'monitor, the return value depends on the
'value of dwFlags. Available values are:
'MONITOR_DEFAULTTONEAREST: Returns a handle to the
' display monitor that is
' nearest to the window.
'MONITOR_DEFAULTTONULL: Returns NULL
'MONITOR_DEFAULTTOPRIMARY: Returns a handle to the
' primary display monitor.
GetMonitorByRect = MonitorFromRect(rc, MONITOR_DEFAULTTONEAREST)
End Function
|