开发者

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 a开发者_StackOverflow中文版round 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


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.


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


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

For example, the menu will be SM_CXMENU and SM_CYMENU.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜