Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetWindowRect(GetDesktopWindow(), &rect); will always yield rect.left == rect.top == 0, right?

1 view
Skip to first unread message

Eric Lilja

unread,
Jan 5, 2005, 6:55:55 PM1/5/05
to
Hello, as the title says:
RECT rect;
GetWindowRect(GetDesktopWindow(), &rect);
rect.top and rect.left will always equal 0 if the above calls succeed,
right?
Just wanted to make sure so I can simplify some calculations a bit.

/ Eric


Tim Robinson

unread,
Jan 5, 2005, 7:02:38 PM1/5/05
to

I don't think you can rely on this in a multi-monitor setup. MSDN says
that the window returned by GetDesktopWindow covers the entire screen. A
monitor above or to the left of the primary monitor has negative
coordinates. Therefore if the primary monitor is not the leftmost or
topmost monitor, GetDesktopWindow will have rect.left != 0 or rect.top != 0.

In short: no, you can't rely on it.

--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/

Tim Robinson

unread,
Jan 5, 2005, 7:07:08 PM1/5/05
to

Nope, looks like I'm wrong.

"Multiple Monitor System Metrics" says:

The rectangle of the desktop window returned by GetWindowRect or
GetClientRect is always equal to the rectangle of the primary
monitor, for compatibility with existing applications. Thus, the
result of

GetWindowRect(GetDesktopWindow(), &rc);
will be:

rc.left = 0;
rc.top = 0;
rc.right = GetSystemMetrics (SM_CXSCREEN);
rc.bottom = GetSystemMetrics (SM_CYSCREEN);

So it looks like you're safe.

Eric Lilja

unread,
Jan 5, 2005, 7:16:01 PM1/5/05
to

Thanks for the quick reply, Tim. It's nice because it simplifies some
calculations a bit, but being a bit paranoid I decided to leave an assertion
in just in case.

/ Eric


Severian

unread,
Jan 5, 2005, 10:12:59 PM1/5/05
to

Keep in mind that any window other than the desktop window may have
negative window coordinates. (Because of the arrangement of my
physical desk, my primary monitor is at (0, 0, 1600, 1200), while my
second monitor is at (-1600, 0, 0, 1200)).

--
Sev

0 new messages