Wednesday, April 29, 2009

Mouse Capture

'Mouse Capture



Private Type POINTAPI

X As Long

Y As Long

End Type



Private Declare Function SetCapture
Lib "user32" _

(ByVal hwnd As Long) As Long

Private Declare Function ReleaseCapture
Lib "user32" () As Long

Private Declare Function GetCursorPos
Lib "user32" _

(lpPoint As POINTAPI) As Long



Dim Pt As POINTAPI



Private Sub Form_Load()

'redirect all mouse input to this form

   
SetCapture Me.hwnd

End Sub



Private Sub Form_MouseDown(Button As Integer, _

Shift As Integer, X As Single, Y As Single)

ReleaseCapture

SetCapture Me.hwnd

End Sub



Private Sub Form_MouseMove(Button As Integer, _

Shift As Integer, X As Single, Y As Single)

'Get the current cursor position

GetCursorPos Pt

Me.CurrentX = 0

Me.CurrentY = 0

'Clear the screen

Me.Cls

Me.Print "Cursor position:"

'Print the mouse coördinates to the form

Me.Print "X:" + Str$(Pt.X) + " Y:" + Str$(Pt.Y)

Me.Print " (Press ALT-F4 to EXIT)"

SetCapture Me.hwnd

End Sub



Private Sub Form_MouseUp(Button As Integer, _

Shift As Integer, X As Single, Y As Single)

ReleaseCapture

SetCapture Me.hwnd

End Sub









 

No comments:

Post a Comment