Solved

VC++ - problem with GetWindowRect()

Posted on 1998-06-12
4
308 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:englm
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1165747
Answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165748
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
 

Author Comment

by:englm
ID: 1165749
I'm not sure exactly what the two coordinate sytems are doing, but it seemed to cure my problem.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165750
They aren't "doing" anything.  Its just the fact that the rectangle's position is measured from different points at different times.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question