''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 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 POINTAPI
x As Long
y As Long
End Type
Private Declare Function MonitorFromPoint Lib "user32" _
(ByVal x As Long, ByVal y As Long, _
ByVal dwFlags As Long) As Long
Private Declare Function ClientToScreen Lib "user32" _
(ByVal hwnd As Long, _
lpPoint As POINTAPI) As Long
Private Function GetMonitorByPoint(x As Single, y As Single) As Long
'Returns a handle to the display monitor
'that contains a specified point.
'
'If the point is contained by a display
'monitor, the return value is a handle
'to that display monitor.
'
'If the point is not contained by 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.
Dim pt As POINTAPI
pt.x = x \ Screen.TwipsPerPixelX
pt.y = y \ Screen.TwipsPerPixelY
'convert form coordinates to screen coordinates
ClientToScreen Me.hwnd, pt
GetMonitorByPoint = MonitorFromPoint(pt.x, pt.y, MONITOR_DEFAULTTONEAREST)
End Function
|