Solved

How to use GetCursorPos

Posted on 1998-08-30
5
693 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

739 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