这个示例只能取得鼠标在客户区的坐标,打包下载区有更好的例子鼠标计程器(MouseTracker),可取得鼠标所在任意位置的坐标
模块
Option Explicit
Type PointAPI
X As Long
Y As Long
End Type
Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
窗体:
Private Sub Form_MouseMove(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Dim Pnt As PointAPI ' Declare a variable to use the UDT
GetCursorPos Pnt ' Call the API to return the x and y
coordinates of the mouse pointer
Me.Cls
Me.Print "MousePointer is located at "; Pnt.X; ","; Pnt.Y
End Sub