Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 712
Ljdawson Avatar asked Jun 12 '26 02:06

Ljdawson


1 Answers

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.

like image 66
GManNickG Avatar answered Jun 13 '26 16:06

GManNickG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!