Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get coordinates of child control relative to parent

815 views
Skip to first unread message

Leto

unread,
Dec 29, 2008, 12:54:18 PM12/29/08
to
Hi Guys

There're only two API calls to get a Windows coordinates (and a few others
which return both of these at once).

One is GetClientRect which returns the window extent (0,0-width, height) and
the other is GetWindowRect which returns (left, top-right, bottom).

My problem is I need to reposition controls on a dialog and neither of these
provide the child control coordinates relative to the parent window.

I have tried GetWindowRect for both parent and child and subtracting.
Unfortunately this seems to include the border and stuff. Is there a
border/window style indepenent way of getting a child controls coordinates
relative to the parent.

MoveWindow usually accepts screen coords unless it's a child window, in
which case it'll only accept client coordinates (which appear to be relative
to the client area of the parent, i.e. excluding borders).

Cheers
Leto


David Lowndes

unread,
Dec 29, 2008, 2:14:50 PM12/29/08
to
>There're only two API calls to get a Windows coordinates (and a few others
>which return both of these at once).
>
>One is GetClientRect which returns the window extent (0,0-width, height) and
>the other is GetWindowRect which returns (left, top-right, bottom).
>
>My problem is I need to reposition controls on a dialog and neither of these
>provide the child control coordinates relative to the parent window.
>
>I have tried GetWindowRect for both parent and child and subtracting.

ClienToScreen & ScreenToClient are probably the missing links (APIs)
you need.

Dave

Remy Lebeau

unread,
Dec 29, 2008, 7:48:38 PM12/29/08
to

"David Lowndes" <Dav...@example.invalid> wrote in message
news:j47il4931or1pn4sb...@4ax.com...

> ClienToScreen & ScreenToClient are probably the missing links
> (APIs) you need.

Alternatively, you can use MapWindowPoints() instead, ie:

RECT r = {0};
::GetClientRect(hWnd, &r);
::MapWindowPoints(hWnd, ::GetParent(hWnd), (LPPOINT) &r, 2);

--
Remy Lebeau

Leto

unread,
Dec 30, 2008, 6:37:57 AM12/30/08
to
Thanks guys. That's worked a treat.

"Remy Lebeau" <no....@no.spam.com> wrote in message
news:eHZLkhha...@TK2MSFTNGP03.phx.gbl...

0 new messages