Pinpoint pixel

K

ksel

I want to open a picture in a form and with a mouse click
output the position of the mouse pointer within the
picture, i.e. the verticle and horizontal pixel. The part
I don't have is accessing the position of the mouse.
 
B

Bob Phillips

This is how to get the cursor position

Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

End Sub

Public Function GetPos() As Long
Dim pPosition As POINTAPI
Dim lReturn As Long

On Error Resume Next

lReturn = GetCursorPos(pPosition)
Application.StatusBar = "x co-ordinate: " & pPosition.x & ", y
co-ordinate: " & pPosition.y

End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

Spurious End Sub in there, should be

Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

Public Function GetPos() As Long
Dim pPosition As POINTAPI
Dim lReturn As Long

On Error Resume Next

lReturn = GetCursorPos(pPosition)
Application.StatusBar = "x co-ordinate: " & pPosition.x & ", y
co-ordinate: " & pPosition.y

End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
K

ksel

Thanks, this really works.

-----Original Message-----
This is how to get the cursor position

Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

End Sub

Public Function GetPos() As Long
Dim pPosition As POINTAPI
Dim lReturn As Long

On Error Resume Next

lReturn = GetCursorPos(pPosition)
Application.StatusBar = "x co-ordinate: " & pPosition.x & ", y
co-ordinate: " & pPosition.y

End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top