I used to do the following to create a window of an 800*600 client area:
dwStyle = WS_OVERLAPPED | WS_THICKFRAME | WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
int nPositionX = 20, nPositionY = 20;
hWindowHandle = CreateWindow( L"CGFramework", wszWndCaption,
dwStyle, nPositionX, nPositionY,
800 + GetSystemMetrics( SM_CXSIZEFRAME )*2,
600 + GetSystemMetrics( SM_CYSIZEFRAME )*2
+ GetSystemMetrics( SM_CYCAPTION ),
0, 0, hInstance, 0
);
Then when querying the client rect with GetClientRect, I used to get 800*600, but now I upgraded my Visual Studio 2008 project to VS2012, and now the GetClientRect() function is returning 792*592 instead. This will happen only with the emetic Aero theme and not the Classic Windows theme.
On top of that, the actual size of the window being created is 804*629, for which I see no reason as the resizeable frame (from WS_THICKFRAME) is obviously larger than 2 pixels on each side.
So my questions are the following:
- Why 800 + GetSystemMetrics( SM_CXSIZEFRAME )*2 does not yield the window width? I don't see anything else than the plain window borders and the client area.
- Why 800 + GetSystemMetrics( SM_CXSIZEFRAME )*2 is 804? Did you ever see a WS_THICKFRAME border of 2 pixels wide as default? This result is wrong no matter what theme we're talking about, there are no such 2px borders. The true borders I got are like 5 or 6 px wide, which adds to the nonsense of these values.
- Why this only happens with VS2012 and not with other compiler versions?
- Why this happens differently in windows 7 aero and windows 8 aero? Shouldn't the behaviour be the same for both OS? The same executable will work perfect with classic theme in W7, will yield wrong sizes in W7 Aero, and will completely broke my window contents in W8--probably because I'm using WinAPI functions to create a proper D3D backbuffer. For some reason it will work fine in W7 Aero AND W8 if the app is compiled with an older version of the compiler, such as VS 2008.
I don't mind if I can get a proper window size through other means; I just want to know why the common procedures -which were valid for the last 15 years or so- don't work anymore. If your answer will be just "use AdjustWindowRect" then please don't answer as I'm asking something different here. I might not even be able to use that function so I'd like to know why the broken numbers I get must be that way.
What I thought was that the function GetSystemMetrics() is actually returning the size of THE BORDERS OF THE BORDERS, as I see them as the only thing that can measure 2 pixels (and actually they are 1 pixel on each side of the border.. it still doesn't make any sense to me)
PS: Changing DPI Awareness in the project config didn't make any difference.