Solved

VC++ - problem with GetWindowRect()

Posted on 1998-06-12
4
302 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now