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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor position

Status
Not open for further replies.

wbeetge

Programmer
May 2, 2002
57
ZA
How can I determine the absolute cursor position inside an activeX, inside a set of containers, inside a form?

I have tried the GetCursorPos API, but it still only returns the relative position. I tried to find the control's Parent left position, but it seems to only work up to the 2nd level: Ctrl -> Ctrl -> Form

I need to determine the absolute position for (n) number of levels.
Thanks in advance.

Graham
 
You need to call the ScreenToClient function after calling GetCursorPos.

ScreenToClient will convert the screen coordinates to client coordinates of the window whose handle is passed to it.
___

Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

...

Dim P As POINTAPI
GetCursorPos P
ScreenToClient ContainerX.hwnd, P
'Now P.x and P.y contain mouse
'position w.r.t. ContainerX.
 
Thanks Hypetia.
I'm going to try it right now.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top