views:

49

answers:

3

When creating a window using CreateWindow(...), which requires the window width and height, I have to enter the values 656 and 516, instead of 640 and 480, so as to account for the windows border.

I'm wondering if there is a way to create a window based only on the portion of the window not including the border, especially considering that if different versions of windows have different size borders, than the program might be displayed differently when I run it on said different versions

(ie: using 640 - object.width will place the object not quite on the edge of the screen if the user's version of windows has different sized borders).

So is there a way to create a window based only on the portion of the screen relevant to the program, or at the vary least a function along the lines of GetVericalBorder()/GetHorizontalBorder() so that I use these in CreateWindow()'s parameters instead of arbitrary and vague values like 656 and 516?

+3  A: 

Have a look at AdjustWindowRectEx. You pass this function a rectangle containing the desired size of your windows' client area, and the window style flags, and it calculates how big to make the overall window so that the client area is the desired size.

John Knoeller
Just be warned that the CreateWindow function can insert additional windows flags and AdjustWindowRectEx won't do this. So if you aren't getting the correct result then try playing with the flags to find which one you missed (or just ask the created window what its flags are).
Grant Peters
Does this change the window itself, or just give me a rectangle whose dimensions I can use in CreateWindow(...)?
Keand64
It just gives you back a rectangle. actually resizing the window is up to you.
John Knoeller
+2  A: 

You can use the SystemParametersInfo() API to get this kind of window information. See the SPI_GETBORDER and/or SPI_GETNONCLIENTMETRICS parameters information here: http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx.

SystemParametersInfo should allow you to account for borders, menus, etc.

Neal S.
A: 

int WINAPI GetSystemMetrics( __in int nIndex ); http://msdn.microsoft.com/en-us/library/ms724385%28VS.85%29.aspx

luca