要想让鼠标控制在指定的区域内不让出来,这个代码怎么写呀?
使用 API 函数 ClipCursor,声明语句如下(同它一起声明的还有一个类型 RECT):
Public Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
例子:
Option Explicit
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim rectRange As RECT '光标锁定范围
'设定光标锁定范围(从左边 0 像素、顶部 0 像素到右边 800 像素、底部 800 像素)
With rectRange
.Left = 0
.Top = 0
.Right = 800
.Bottom = 800
End With
'锁定
ClipCursor rectRange
'下面这个语句可以取消锁定(注: 锁定时按下 Windows 徽标键或退出当前程序也可取消锁定)
'ClipCursor Null
End Sub
[此贴子已经被作者于2006-1-22 20:32:31编辑过]