Option Explicit
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim WithEvents hWndMouse As VB.Timer
Event MouseMove(Button As MouseButtonConstants, Shift As ShiftConstants, X As Single, Y As Single)
Event MouseOver(Button As MouseButtonConstants, Shift As ShiftConstants, X As Single, Y As Single)
Event MouseOut()
Private Property Get IsMouse() As Boolean
Dim Cur As POINTAPI
GetCursorPos Cur
IsMouse = UserControl.hWnd = WindowFromPoint(Cur.X, Cur.Y)
End Property
Private Sub hWndMouse_Timer()
If Not IsMouse Then
hWndMouse.Interval = 0
RaiseEvent MouseOut
End If
End Sub
Private Sub UserControl_Initialize()
Set hWndMouse = Controls.Add("VB.Timer", "检测句柄")
End Sub
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If IsMouse And hWndMouse.Interval = 0 Then
RaiseEvent MouseOver(CLng(Button), CLng(Shift), X, Y)
hWndMouse.Interval = 100
Else
RaiseEvent MouseMove(CLng(Button), CLng(Shift), X, Y)
End If
End Sub