Solved

How to use GetCursorPos

Posted on 1998-08-30
5
692 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

820 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