'*************************************************************************
'**函 数 名:UserControl_MouseMove
'**输 入:
'**输 出:无
'**功能描述:设置鼠标移动事件,鼠标离开事件
'**全局变量:
'**调用模块:
'**作 者:
'**日 期:
'**修 改 人:
'**日 期:
'**版 本:版本1.0
'*************************************************************************
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X >= 0 And X <= UserControl.Width And Y >= 0 And Y <= UserControl.Height Then
RaiseEvent MouseMove(Button, Shift, X, Y)
Call SetCapture(UserControl.hwnd) '捕获鼠标
Else
RaiseEvent MouseLeave
Call ReleaseCapture '释放鼠标
End If
End Sub
为了感谢大家的支持,我将代码帖出来:
Private Sub timDetectPos_Timer()
Dim hwndContainer As Long
Dim posCurrent As POINTAPI
Dim posContainer As POINTAPI
Dim R As RECT
Dim lRet As Long
Private Sub UserControl_Paint()
UserControl.Cls
Print "Caption"
End Sub
问题来了:
一、无窗口控件的MouseMove事件本身就不会触发(即Usercontrol_Mousemove),只有
UserControl_HitTest事件。
二、在UserControl_HitTest中SetCapture无效。
Private Sub UserControl_HitTest(X As Single, Y As Single, HitResult As Integer)
Dim MouseOver As Boolean
MouseOver = (0 <= X) And (X <= UserControl.Width) And (0 <= Y) And (Y <= UserControl.Height)
If MouseOver = False Then Stop
If MouseOver Then
SetCapture UserControl.hwnd
UserControl.ForeColor = RGB(255, 0, 255)
Else
UserControl.ForeColor = RGB(0, 255, 0)
ReleaseCapture
End If
End Sub
在上面的代码中,MouseOver 始终=True。