Home > Archive > MSDN > May 2005 > GetWindowRect returns what?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
GetWindowRect returns what?
|
|
| Vaclav 2005-05-29, 8:55 pm |
| According to all articles about GetWindowRect it returns positon relative to
"upper left corner". However, when I try MoveWindow into this position it
does not move into area advertized.
What am I missing?
| |
|
| The GetWindowRect function retrieves the dimensions of the bounding rectangle
of the specified window. The dimensions are given in screen coordinates that
are relative to the upper-left corner of the screen.
If you are moving to return value of GetWindowRect then you are moving the
window to the same place. What are your cordinates? (0,0) should be top left
of desktop. Watch out for task bars at top of desktop! I hate it when
windows hide them selves under the task bar.
"Vaclav" wrote:
> According to all articles about GetWindowRect it returns positon relative to
> "upper left corner". However, when I try MoveWindow into this position it
> does not move into area advertized.
> What am I missing?
>
>
| |
| Vaclav 2005-05-30, 3:55 am |
|
"Terry" wrote:
[color=darkred]
> The GetWindowRect function retrieves the dimensions of the bounding rectangle
> of the specified window. The dimensions are given in screen coordinates that
> are relative to the upper-left corner of the screen.
>
> If you are moving to return value of GetWindowRect then you are moving the
> window to the same place. What are your cordinates? (0,0) should be top left
> of desktop. Watch out for task bars at top of desktop! I hate it when
> windows hide them selves under the task bar.
>
> "Vaclav" wrote:
>
Here is my test code .
Basically I have two CStatic "objects" in the CFormView - created in
associated
dialog.
I want to move them together, side by side.
I can get the CDC pointer and can draw a test line from upper left corner to
the lower right corner using eitherGetClientRect or GetWindowRect( followed
by ScreenToClient).
Both of these "methods" apparently set the object window origin to upper
left corner of the objects.
GetWindowRect retruns what appears to be relative coordinates at random
origin, but they are the dimensions of the objects!
I am using
m_test.GetWindowRect(&rect1);
without using
m_test.ScreenToClient(&rect1);
When I use MoveWindow on m_test object it moves into these coorinates which
ARE NOT correct.
I must be doing something wrong!
. Either[color=darkred]
CBrush brush(RGB(255,0,0));
CPen pen(PS_SOLID,10,RGB(0,0,0));
CPen pen1(PS_SOLID,5,RGB(255,0,0));
CDC *pDC = m_test.GetDC();
m_test.GetClientRect(&rect);
/*
m_test.GetWindowRect(&rect1);
m_test.ScreenToClient(&rect1);
pDC->SelectObject(pen);
pDC->MoveTo(rect.left,rect.top);
pDC->LineTo(rect.right,rect.bottom);
pDC->SelectObject(pen1);
pDC->MoveTo(rect1.left,rect1.top);
pDC->LineTo(rect1.right,rect1.bottom);
*/
//CPen pen1(PS_SOLID,2,RGB(0,255,0));
CDC *pDC1 = m_test1.GetDC();
pDC1->SelectObject(pen1);
// m_test1.GetClientRect(&rect1);
m_test1.GetWindowRect(&rect2);
m_test1.ScreenToClient(&rect2);
pDC1->MoveTo(rect1.left,rect1.top);
pDC1->LineTo(rect2.right,rect2.bottom);
| |
| Jeff Partch [MVP] 2005-05-30, 3:55 pm |
| "Vaclav" <Vaclav@discussions.microsoft.com> wrote in message
news:65E08BE2-8D47-4C5F-81B9-2464F42F0F13@microsoft.com...
> Here is my test code .
> Basically I have two CStatic "objects" in the CFormView - created in
> associated
> dialog.
> I want to move them together, side by side.
> I can get the CDC pointer and can draw a test line from upper left corner
to
> the lower right corner using eitherGetClientRect or GetWindowRect(
followed
> by ScreenToClient).
> Both of these "methods" apparently set the object window origin to upper
> left corner of the objects.
>
> GetWindowRect retruns what appears to be relative coordinates at random
> origin, but they are the dimensions of the objects!
> I am using
> m_test.GetWindowRect(&rect1);
> without using
> m_test.ScreenToClient(&rect1);
>
> When I use MoveWindow on m_test object it moves into these coorinates
which
> ARE NOT correct.
> I must be doing something wrong!
My guess is that after calling m_test.GetWindowRect you need to then call
the parent CFormView's ScreenToClient before calling m_test.MoveWindow.
--
Jeff Partch [VC++ MVP]
|
|
|
|
|