VB声明
Declare Function SetCapture Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As Long
说明
将鼠标捕获设置到指定的窗口。在鼠标按钮按下的时候,这个窗口会为当前应用程序或整个系统接收所有鼠标输入
返回值
Long,之前拥有鼠标捕获的窗口的句柄
参数表
参数 类型及说明
hwnd Long,要接收所有鼠标输入的窗口的句柄
注解
我的理解:与ReleaseCapture函数一起使用,用于判断鼠标离开(mouseleave)事件
ReleaseCapture
VB声明
Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long
说明
为当前的应用程序释放鼠标捕获
返回值
Long,TRUE(非零)表示成功,零表示失败
注解
我的理解:与SetCapture函数一起使用,用于判断鼠标离开(mouseleave)事件
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
SetCapture Command1.hwnd
If X < 0 Or X > Command1.Width Or Y < 0 Or Y > Command1.Height Then
Debug.Print "鼠标已离开"
ReleaseCapture
End If
End Sub