Solved

How to use GetCursorPos

Posted on 1998-08-30
5
686 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:smithgr
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 100 total points
ID: 1431958
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

0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1431959
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

0
 
LVL 1

Author Comment

by:smithgr
ID: 1431960
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
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1431961
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
0
 
LVL 1

Author Comment

by:smithgr
ID: 1431962
Thanks once again Mike!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now