API真多,可惜能用于恶作剧得太少了。前几天好不容易找到一个好课题,谁知道VB不支持“回调函数”,老是出“非法操作”。唉,没办法,用旧API写个恶作剧吧。旧瓶装新酒了!^_^
先在模块中声明一下,都是旧API了,不用解释了!
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
然后在窗体中放入一个“Timer”,设Interval为100,在Form_Load中写上Me.Hide。烦死了,每次都是这几句话。
再为“Timer”写代码:
Private Sub Timer1_Timer()
Dim myPoint As POINTAPI
Dim STX, STY As Integer
Static myRect As RECT
Static xRate, yRate As Integer
Static notFirst As Boolean
STX = Screen.Width / Screen.TwipsPerPixelX
STY = Screen.Height / Screen.TwipsPerPixelY
If Not notFirst Then
With myRect
.Left = STX / 2
.Top = STY / 2
.Right = .Left + 30
.Bottom = .Top + 30
End With
xRate = Rnd * 32 - 16
yRate = Rnd * 32 - 16
notFirst = True
End If
If Rnd < 0.05 Then
xRate = Rnd * 32 - 16
yRate = Rnd * 32 - 16
End If
With myRect
.Left = .Left + xRate
If .Left < 0 Then
xRate = -xRate
.Left = -.Left
End If
.Right = .Left + 30
If .Right > STX Then
xRate = -xRate
.Right = 2 * STX - .Right
.Left = .Right - 30
End If
.Top = .Top + yRate
If .Top < 0 Then
yRate = -yRate
.Top = -.Top
End If
.Bottom = .Top + 30
If .Bottom > STY Then
yRate = -yRate
.Bottom = 2 * STY - .Bottom
.Top = .Bottom - 30
End If
End With
GetCursorPos myPoint
With myRect
If myPoint.x > .Left And myPoint.x < .Right And _
myPoint.y > .Top And myPoint.y < .Bottom Then
ClipCursor myRect
End If
End With
End Sub
看懂了吗?捕鼠器!制作一个看不见的矩形。如果鼠标进入了矩形,就出不来了!真是无聊!
我用C不太++做了一个免安装的,下载去试试。和VB版的稍有不同,鼠标被捕后只扣押10秒钟,而不是“无期徒刑”。我不知道在VB中怎样写NULL指针,因此我无法在VB中释放被捕的鼠标。请高手指教。