Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXCEL: API call 'ScreentoClient': seeing no conversion

Status
Not open for further replies.

jadadad

Technical User
Jun 2, 2004
12
US
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 is supposed to be the hWnd parameter ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top