PDA

Click to See Complete Forum and Search --> : Cursor Position


Sep 11th, 2000, 11:11 PM
hey there everybody... umm... quick question...
i know how to get the raw cursor position on the
screen with an API call... but is it possible to
get cursor position _relative_ to a form or
control, such as a picture box?

Dubious, 2K

kedaman
Sep 12th, 2000, 09:15 AM
There's a api called clienttowindow, look here:
http://forums.vb-world.net/showthread.php?threadid=20557

Sep 12th, 2000, 03:49 PM
Add the following to a Form with a Timer.

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type

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

Private Sub Timer1_Timer()
Dim PT As POINTAPI
GetCursorPos PT

Cls
Print PT.x - (Me.Left / Screen.TwipsPerPixelX) & "," & PT.y - (Me.Top / Screen.TwipsPerPixelY)
End Sub

kedaman
Sep 13th, 2000, 03:12 AM
What are you trying to demonstrate meg? the declaration of ClienttoWindow but not the usage?

opus
Sep 15th, 2000, 02:00 PM
Maybe I don't get the point, but for the same problem, i.e.
getting the cursor coordinates (x,y) I'm just using standard VB stuff. The x and y will be given in the used scalemode (i.e. pixel, twips or whatever)
/code
sub picturebox.mouse_move
ActualCursorX=X
ActualCursorY=Y
end sub
/code

Sep 15th, 2000, 02:15 PM
Private Declare Function SetCapture Lib "user32.dll" (ByVal hWnd As Long) As Long

Private Declare Function ReleaseCapture Lib "user32.dll" (ByVal hWnd As Long) As Long

Private Sub Command1_Click()
SetCapture Picture1.hWnd
End Sub

Private Sub Command2_Click()
ReleaseCapture Picture1.hWnd
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print X, Y
End Sub

by first click of the mouse the picturebox get the event and it make automaticaly a ReleasCapture

by the next click of the mouse the right control or form get the event

gwdash
Sep 15th, 2000, 04:09 PM
if you use SetCapture & Release Capture, then other windows won't proccess clicks, it will all be sent to your program