?
Solved

How to get x and y coordinates of cursor..

Posted on 2004-08-18
3
Medium Priority
?
219 Views
Last Modified: 2010-05-02
In a module, I have:

Type PointApi
  x As Long
  y As Long
End Type

Declare Function GetCursorPos Lib "user32" (IpPoint As PointApi) As Long
‘’’’’’’’’’’’’’
In a cmdButton_Click, I have

Private Button1_Click()
Dim p As PointApi
Dim xp As Long
Dim yp As Long
xp = GetCursorPos(p)
yp = GetCursorPos(p)
MsgBox xp & ", " & yp          ‘<---  no matter where I click, I get 1, 1

End Sub

Also, I would like to get the Button1.Top and Button1.Left as well.  Thank you in advance for your input.

Mike
0
Comment
Question by:Mike Eghtebas
[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 Comments
 
LVL 19

Accepted Solution

by:
Shauli earned 1200 total points
ID: 11837185
I dont know what you want to acheive with the command button, however, using the MouseDown event you can get the precise location of the mouse using the integrated X and Y variables:

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'where X and Y are the mouse location
'do your stuff
End Sub


S
0
 

Assisted Solution

by:Imbue
Imbue earned 800 total points
ID: 11837191
Try using this code in the command button.


Dim p As PointApi

Call GetCursorPos(p)
MsgBox p.x & ", " & p.y
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 11837451
Shauli,
Thank you very much for good directions I have been receiving from you.  

Imbue,  
Thank you for your solution.

Regards,

Mike
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

801 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