Solved

How to use GetCursorPos

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

744 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

14 Experts available now in Live!

Get 1:1 Help Now