在标准EXE工程添加一个Timer、两个Label控件,各属性取默认值。然后给工程拷贝如下代码:
Option Explicit
'申明API函数
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI ' 声明数据类型
x As Long
y As Long
End Type
Dim z As POINTAPI ' 变量
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
GetCursorPos z ' 获取坐标
Label1 = "x: " & z.x ' 显示 x 坐标
Label2 = "y: " & z.y ' 显示 y 坐标
End Sub