'変数の明示的な宣言を強制します。
Option Explicit
'マウスカーソルの位置がスクリーン座標で格納される構造体
Private Type POINTAPI
x As Long
y As Long
End Type
'API関数 GetCursorPos の使用を宣言します。
Private Declare Function GetCursorPos Lib "user32"
(lpPoint As POINTAPI) As Long
'変数を宣言する
Dim ret As Long
Dim myCurPos As POINTAPI
Private Sub Form_Load()
Form1.Caption = "マウスカーソルの位置を取得する方法(API関数GetCursorPosの使用例)"
Label1.Caption = ""
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
ret = GetCursorPos(myCurPos)
Label1.Caption = "X座標 " & myCurPos.x & "
: " & "Y座標 " & myCurPos.y
End Sub