add a new module to your project and slap this in it
Window is the window that the coordinates are based in, for example if the coords are relitive to Picture1 then Window would be Picture1.Code:Option Explicit Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long Public Function IsCursorInBox(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal y2 As Single, Window As Object) Dim apiPos As POINTAPI Dim x As Single Dim y As Single Dim retval As Boolean On Error GoTo ERR_IsCursorInBox: GetCursorPos apiPos ScreenToClient Window.hwnd, apiPos x = Window.ScaleX(apiPos.x, Window.ScaleMode, vbPixels) y = Window.ScaleY(apiPos.y, Window.ScaleMode, vbPixels) retval = x > x1 retval = retval And x < x2 retval = retval And y > y1 retval = retval And y < y2 IsCursorInBox = retval Exit Function ERR_IsCursorInBox: Err.Raise 13 End Function
It Only works on Forms and Pictureboxes.




Reply With Quote