Click to See Complete Forum and Search --> : Determining X and Y coordinates of a control
MicahCarrick
Nov 29th, 1999, 01:08 AM
Is there any way I can figure out what the X and Y coordinates of a control are without knowing that of the form it's on or it's own left and top properties? Perhaps through it's hWnd or something?
I want to be able to establish a control's position with reference to the entire screen, but won't know the form it's on's position, nor it's position on that form.
Any help would be much appreciated. Thanks,
Micah Carrick
Aaron Young
Nov 29th, 1999, 02:31 AM
You could use the GetWindowRect if you know the Window Handle of the Control, eg.
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim tRECT As RECT
Dim tPOINT As POINTAPI
Dim lHwnd As Long
Call GetCursorPos(tPOINT)
lHwnd = WindowFromPoint(tPOINT.x, tPOINT.y)
Call GetWindowRect(lHwnd, tRECT)
Caption = tRECT.Left & ", " & tRECT.Top
End Sub
Point to any Window/Control to get it's Left and Top Coords Relative to the Top Left of the Screen in Pixels.
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
MicahCarrick
Nov 29th, 1999, 02:36 AM
Thank you very much :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.