I’ve tried the code below on three different “things”. The first one was a simple rectangle that I drew and assigned the macro below. Every time I clicked on the rectangle, I’d get the screen coordinates, and not the coordinates in relationship of the rectangle, where 0,0 is in the upper left had corner of the rectangle. Secondly, I’ve displayed a userform and using the same code below, got the same results as the rectangle...screen coordinate system. Thirdly, I added an image to the userform (using the image icon from the tool box) and then called the macro below everytime the mouse button was pressed on the image. Once again, I got the screen coordinate system.
What I was hoping was for “ScreenToClient” would convert the screen coordinate system to “client” coordinate system where the client was either one of the three listed above. I sure could use some insight on this one.
Thanks.
++++++++++++++++
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Sub MouseClicked()
Dim pt As POINTAPI
Dim lRetVal As Long
Dim lValRet As Long
'
' See where the mouse is.
Call GetCursorPos(pt)
' Convert into client coordinates.
Call ScreenToClient(hWnd, pt)
'
MsgBox "My Position:" & vbLf & pt.x & "," & pt.y
End Sub
What I was hoping was for “ScreenToClient” would convert the screen coordinate system to “client” coordinate system where the client was either one of the three listed above. I sure could use some insight on this one.
Thanks.
++++++++++++++++
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Sub MouseClicked()
Dim pt As POINTAPI
Dim lRetVal As Long
Dim lValRet As Long
'
' See where the mouse is.
Call GetCursorPos(pt)
' Convert into client coordinates.
Call ScreenToClient(hWnd, pt)
'
MsgBox "My Position:" & vbLf & pt.x & "," & pt.y
End Sub