VB API学习(三)——判断鼠标移动

Eddy 发布于2010-1-3 11:20:41 分类: 程序设计 已浏览loading 网友评论0条 我要评论

今日主角:SetCapture、ReleaseCapture

API注解:

VB声明
Declare Function SetCapture Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As Long
说明
将鼠标捕获设置到指定的窗口。在鼠标按钮按下的时候,这个窗口会为当前应用程序或整个系统接收所有鼠标输入
返回值
Long,之前拥有鼠标捕获的窗口的句柄
参数表
参数 类型及说明
hwnd Long,要接收所有鼠标输入的窗口的句柄

VB声明
Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long
说明
为当前的应用程序释放鼠标捕获
返回值
Long,TRUE(非零)表示成功,零表示失败

实例代码:

Option Explicit     '判断鼠标的Move
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long ' ')
Private Sub text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Text1
     If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
         .Text = "里面"
         ReleaseCapture
     Else
         .Text = "外面"
         SetCapture .hWnd
     End If
End With
Label1.Caption = "X: " & X
Label2.Caption = "Y: " & Y
End Sub

[VB—API 学习(一)]

[VB API学习(二)——限定光标移动范围]

已经有(0)位网友发表了评论,你也评一评吧!
原创文章如转载,请注明:转载自Eddy Blog
原文地址:http://www.rrgod.com/program/306.html     欢迎订阅Eddy Blog

关于 VB  SetCapture  ReleaseCapture  的相关文章

记住我的信息,下次不用再输入 欢迎给Eddy Blog留言