Link to home
Start Free TrialLog in
Avatar of englm
englm

asked on

VC++ - problem with GetWindowRect()

I am trying to move an object on top of another object in a view window. I am positioning the second object based on the coordinates returned by GetWindowRect() of the first object. This works fine when the manin view is maximized, however when the view is made smaller so that scroll bars appear, the GetWindowRect() coordinates do not seem to be right. When I try to put the second object to a position of
object1rect.top (which is of CRect type) they do not match up. How can get an accurate position of the first object to determine where to put the second?
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

GetWindowRect returns coordinates that are relative to the top-left corner of the screen.  However, when you move a window, you specify coordinates that are relative to the top-left corner of the window's parent's client area.    The you need to convert the coordinates from screen coordinates to the parent windows client coordinates, before the move.  This is done with ScreenToClient().

Note, if the parent window is maximized, then its client area's top-left corner is almost at the screen's top-left corner.  Thus the two coordinate systems are almost aligned.  That is why you don't see the problem with a maximized parent window.  However, the problem was still there.

If you have any questions, ask.
Avatar of englm

ASKER

I'm not sure exactly what the two coordinate sytems are doing, but it seemed to cure my problem.
They aren't "doing" anything.  Its just the fact that the rectangle's position is measured from different points at different times.