9

If I maximize a Delphi form the width and height values are 8 pixles greater that the corresponding GetSystemMetrics SM_CXSCREEN and SM_CYSCREEN?

For Example:

When I right click on my screen and get properties I have a 1680 X 1050 screen resolution. Those are the same values returned from GetSystemMetrics(SM_CXSCREEN) and GetSystemMetrics(SM_CYSCREEN).

When I maximize the form in my Delphi application I get a width of 1688 and a height of 1058. There is an 8 pixel difference. What causes this difference?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Read `ClientWidth` and `ClientHeight` and you should see the same values as from `GetSystemMetrics` (I guess). – TLama Feb 02 '13 at 23:14
  • 1
    Maybe it's because window's client area is maximized - window's chrome is outside the screen. – Spook Feb 02 '13 at 23:14
  • 2
    Yes, @Spook, this is how Windows works, IIRC. And TLama is right, too. [But if you have multiple monitors, the part of the maximised window's border that is not on 'its' monitor is not shown on any neighbouring monitor, either.] – Andreas Rejbrand Feb 02 '13 at 23:16
  • 2
    @TLama - I believe ClientHeight does not inclued the aplication's title bar. – Michael Riley - AKA Gunny Feb 02 '13 at 23:50
  • 1
    See also for when this is a problem: [What can I do about maximized, styled windows, which show their borders on adjacent monitors?](http://stackoverflow.com/q/10936906/243614) – Sertac Akyuz Feb 03 '13 at 02:22

2 Answers2

21

When maximized windows were originally implemented, the designers wanted to remove the resizing borders. Rather than removing them, they instead decided to draw those borders beyond the edges of the screen, where they would not be seen. Hence the rather surprising window rectangle of a maximized window.

This implementation decision became a problem with the advent of multi-monitor systems. By that time there were applications that relied on this behaviour and so the Windows team decided to retain the behaviour for the sake of compatibility. This meant that maximized windows leaked onto neighbouring screens. In time the window manager acquired capabilities that meant it could suppress that leakage.

Raymond Chen, as usual, has an article that covers the details: Why does a maximized window have the wrong window rectangle?

Fajela Tajkiya
  • 629
  • 2
  • 10
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
2

I wrote simple program, which catches WM_GETMINMAXINFO. This message allows one to modify position and size of maximized window, before the actual maximization takes place. The default values provided by system were:

Position.x: -8
Position.y: -8
Size.x: 1456 (= 8 + width of screen + 8)
Size.y: 916 (= 8 + height of screen + 8)

The resolution of my screen is 1440x900.

It seems, that Windows positions the window after the maximization in such way, that the client area covers the most the available space and window's chrome is hidden outside the screen area.

Spook
  • 25,318
  • 18
  • 90
  • 167
  • 1
    You mentioned window's chrome twice here and in a comment above. What is window's chrome? – Michael Riley - AKA Gunny Feb 02 '13 at 23:42
  • 1
    @CapeCodGunny http://en.wikipedia.org/wiki/User_interface_chrome#User_interface_and_interaction_design – David Heffernan Feb 02 '13 at 23:45
  • 1
    It could be also interesting to note that the system provided default values are always for the dimensions of the primary monitor, even if a window is going to be maximized to another monitor. As long as you don't touch the values, the window maximizes fine. – Sertac Akyuz Feb 03 '13 at 02:27