views:

113

answers:

3

Hi everyone, Stuck on a little fiddly problem. I'm creating a GUI in C++ using XP and VS C++ using the command CreateWindow().

My question is, how do I make the inside paintable region a perfect square. When passing in the size of the window to create, some of this is deducted for the menu bar at the top, border all around etc. Are there any real time variables I can pass in, e.g. to create a 500x500 window would be:

...500+BORDER,500+MENU_TOP+BORDER...

Thanks everyone

A: 

you can find all the relevant size (windows framewidth, menubar height, etc) here: GetSystemMetrics(). Using these values you should be able to create a perfect square window

Toad
A: 

You can get all the UI metrics from the GetSystemMetrics() API call.

For example, the menu will be SM_CXMENU and SM_CYMENU.

jeffamaphone
+4  A: 

The way I usually do it is with AdjustWindowRect. I find it simpler than the other suggested methods (which should work just as well, it's your choice). Use it as such:

RECT rect = {0, 0, desiredWidth, desiredHeight};

AdjustWindowRect(&rect, windowStyle, hasMenu);

const int realWidth = rect.right - rect.left;
const int realHeight = rect.bottom - rect.top;

And pass realWidth & realHeight to CreateWindow.

The function will, as its name suggests, adjust the window according to your window style and menu use, so that the client region matches your desired size.

GMan
Works great, thanks!
Laurence Dawson
Not a problem :3
GMan