Pinpoint pixel

  • Thread starter Thread starter ksel
  • Start date Start date
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.
 
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)
 
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)
 
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)




.
 
Back
Top