主题:[讨论]VB如何限制鼠标不能移动???
mxalbert1996
[专家分:780] 发布于 2008-08-14 16:38:00
[em18]如题。
(我已经试过用移动鼠标的API函数配合Timer控件了,但是那样的话,在两次鼠标定位移动之间的时间空隙鼠标还是可以动的)
回复列表 (共6个回复)
沙发
tanchuhan [专家分:15140] 发布于 2008-08-14 16:48:00
API: ClipCursor
板凳
mxalbert1996 [专家分:780] 发布于 2008-08-14 20:30:00
http://www.programfan.com/doc/vbapi/ClipCursor.htm
ClipCursor, ClipCursorBynum
VB声明
Declare Function ClipCursor& Lib "user32" (lpRect As RECT)
Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
说明
将指针限制到指定区域。ClipCursorBynum是一个别名,允许我们清除以前设置的指针剪切区域
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpRect RECT,指定一个矩形,用像素屏幕坐标系统表示。鼠标指针必须在这个区域内运动。如使用函数的ClipCursorBynum形式,则可将参数设为Long值,用它传递一个0,禁止指针剪切,恢复常规运作状态
注解
指针剪切后,按Ctrl+Alt+Del可简单的清除剪切区域
这个页面倒是有,但能不能给我讲讲参数lpRect的详细用法???
3 楼
tanchuhan [专家分:15140] 发布于 2008-08-14 20:55:00
lpRect指向一个屏幕矩形,光标允许在这个矩形内移动
left top right bottom
4 楼
guoyong_cy [专家分:3050] 发布于 2008-08-14 23:33:00
ClipCursor 到一个0面积区域,鼠标就死了,但是用alt+tab切换窗体后会变,可以加上键盘检测,或者检测消息,或者干脆hook它...方法多,当然要看你出于什么用途了
5 楼
mxalbert1996 [专家分:780] 发布于 2008-08-17 16:22:00
那有没有人能给我一个代码呀???谢了!
6 楼
abusww [专家分:60] 发布于 2008-09-20 02:30:00
这是一段从网上转来的代码,希望有用。
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type POINT
x As Long
y As Long
End Type
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Command1.Caption = "Limit Cursor Movement"
Command2.Caption = "Release Limit"
End Sub
Private Sub Command1_Click()
'Limits the Cursor movement to within the form.
Dim client As RECT
Dim upperleft As POINT
'Get information about our wndow
GetClientRect Me.hWnd, client
upperleft.x = client.left
upperleft.y = client.top
'Convert window co?rdinates to screen co?rdinates
ClientToScreen Me.hWnd, upperleft
'move our rectangle
OffsetRect client, upperleft.x, upperleft.y
'limit the cursor movement
ClipCursor client
End Sub
Private Sub Command2_Click()
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
我来回复