フォーム外も含むマウス位置を取得する

 


Option Explicit

Private Type POINTAPI 'カーソル位置情報取得用変数
x As Long
y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


Private Sub Form_Load()
Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Dim Rect As POINTAPI
Dim lngRet As Long

'マウスカーゾルを取得
lngRet = GetCursorPos(Rect)
If lngRet <> 0 Then
Me.Label1 = "X=" & Format$(Rect.x, "@@")
Me.Label2 = "Y=" & Format$(Rect.y, "@@")
End If


End Sub


トップページに戻る

Tips一覧に戻る