Link to home
Start Free TrialLog in
Avatar of smithgr
smithgr

asked on

How to use GetCursorPos

I need to find the X, and Y coordinate position of the mouse on the screen (Whether its on my form or not) how can I do this using the API?  I have searched but do not understand the API calls...Thanks
ASKER CERTIFIED SOLUTION
Avatar of MikeP090797
MikeP090797

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeP090797
MikeP090797

Put this in a module:
Type POINTAPI
        x As Long
        y As Long
End Type
Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long


Now, to get the cursor location, use:

Dim p as POINTAPI
Dim X as long
X=GetCursorPos(p)

'p.X and p.Y will hold the coordinates

Avatar of smithgr

ASKER

MIke, this is great and I have it working...do you know how to tell what the left and top of a form are using the same type of coordinates?  What I'm trying to do is to find if the mouse is outside of my form...Thanks
Sorry it took me so long to respond:

Dim nX as single
Dim nY as single
nX=P.X/Screen.TwipsPerPixelX
nY=P.Y/Screen.TwipsPerPixelY
Avatar of smithgr

ASKER

Thanks once again Mike!