Ljdawson
Ljdawson

Reputation: 12229

Create Square Window C++

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

Upvotes: 3

Views: 802

Answers (3)

GManNickG
GManNickG

Reputation: 504063

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.

Upvotes: 4

i_am_jorf
i_am_jorf

Reputation: 54610

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

For example, the menu will be SM_CXMENU and SM_CYMENU.

Upvotes: 0

Toad
Toad

Reputation: 15935

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

Upvotes: 0

Related Questions