SetCapture的基本应用示例
2004-07-28 09:20 电脑人生 阅读(242) 评论(0) 编辑 收藏 举报怎么样可以捕获到鼠标进入和离开窗体呢?
这里要用到两个Api,即SetCapture和ReleaseCapture.
新建一个工程,将下面代码贴入代码区.按F5运行即可.
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Form1
If Not ((X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height)) Then
ReleaseCapture
If .Caption <> "进来了" Then
.Caption = "进来了"
End If
SetCapture .hwnd
Else
.Caption = "离开了"
End If
End With
End Sub
现在把鼠标移动到窗体内外试试看.
--- 程序:唐细刚