PDA

Click to See Complete Forum and Search --> : Getting the mouse location on the screen


Namo
May 15th, 2000, 03:17 AM
(* Sorry about my english , i am from Israel..)

Hi
How can i get the mouse location of the mouse with API function (x and y for location or whatever...)
what is the name of the function? i will be happy to know how to use it (can you give me an example maybe? )

Thanks!
Namo.

Sam Finch
May 15th, 2000, 05:35 AM
No Problem, There's 2 APIs to use

they all use Private Type POINTAPI
x As Long
y As Long
End Type

which is a type used to store the mouse position


the first is Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long

this fills the structure passed to lpPoint with the coordinates of the mouse on the screen

the other one isPrivate Declare Function ScreenToClient Lib "user32" Alias "ScreenToClient" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
this translates the coordinates in lpPoint from screen coods to the coords of a particular window.

The coords of the mouse position you get are in pixels, you need the scalex and scaley methods to translate this into twips.

for example


Private Type POINTAPI
x As Long
y As Long
End Type


Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim px As Single
Dim py As Long
Dim apiPoint As POINTAPI

GetCursorPos apiPoint 'gets the screen position of the cursor in pixels

ScreenToClient Form1.hwnd, apiPoint 'Tanslates to window coords, still in pixels

px = Form1.ScaleX(apiPoint.x, vbPixels, vbTwips) 'scales coords to pixels
py = Form1.ScaleY(apiPoint.y, vbPixels, vbTwips)

MsgBox x - px 'will always return 0
MsgBox y - py


End Sub


hope this helps

Namo
May 16th, 2000, 02:25 AM
Thank you very very much

Nimrod/namo