Home
How to fire MouseIn and MouseOut events |
Option Explicit
Private MouseIn As Boolean
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As _
Long) As Long
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 Event MouseIn()
Public Event MouseOut()
Public Event MouseMove(Button As Integer, Shift As Integer, X _
As Single, Y As Single)
Private Sub UserControl_MouseMove(Button As Integer, Shift As _
Integer, X As Single, Y As Single)
Dim xyCursor As POINTAPI
Dim Xi As Long
Dim Yi As Long
SetCapture UserControl.hwnd
GetCursorPos xyCursor
ScreenToClient UserControl.hwnd, xyCursor
Xi = xyCursor.X * Screen.TwipsPerPixelX
Yi = xyCursor.Y * Screen.TwipsPerPixelY
If Xi < 0 Or Yi < 0 Or Xi > UserControl.Width Or Yi > _
UserControl.Height Then
If Button > 0 Then
RaiseEvent MouseMove(Button, Shift, X, Y)
End If
If MouseIn Then
RaiseEvent MouseOut
If Button = 0 Then
ReleaseCapture
End If
MouseIn = False
End If
Else
RaiseEvent MouseMove(Button, Shift, X, Y)
If Not MouseIn Then
RaiseEvent MouseIn
MouseIn = True
End If
End If
End Sub
|
© Copyright Notice
Home
|