vb寻找鼠标问题

来源:百度知道 编辑:UC知道 时间:2024/06/10 15:29:06
用vb6,想让鼠标一碰到左上角就执行下一步,怎么办?
是碰到屏幕的左上角。

添加Timer控件,设置Interval属性值大于0,例如10至100之间
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Timer1_Timer()
Static x0, y0, i
Dim p As POINTAPI
GetCursorPos p '获取当前鼠标位置
Caption = p.x & "," & p.y '在窗体标题栏显示鼠标位置,如果没必要可不写
If (x0 <> 0 Or y0 <> 0) And p.x = 0 And p.y = 0 Then
'当p.x = 0 And p.y = 0时,鼠标碰到了屏幕左上角
i = i + 1
Print "鼠标第" & i & "次碰到了屏幕左上角"
'在这里添加要执行的下一步的语句
End If
x0 = p.x
y0 = p.y
End Sub

是碰到哪里的左上角