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?
englmAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
nietodConnect With a Mentor Commented:
Answer coming.
0
 
nietodCommented:
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.
0
 
englmAuthor Commented:
I'm not sure exactly what the two coordinate sytems are doing, but it seemed to cure my problem.
0
 
nietodCommented:
They aren't "doing" anything.  Its just the fact that the rectangle's position is measured from different points at different times.
0
All Courses

From novice to tech pro — start learning today.