WinAPI:创建一个具有指定客户区大小的窗口 [英] WinAPI: Create a window with a specified client area size
问题描述
我想知道如何使用特定的客户区大小使用Win32 API创建窗口。
I was wondering how can I create a window using Win32 API with a specific client area size.
尝试创建窗口时使用以下代码段,整个窗口为640x480,窗口的chrome采用一些客户区:
When trying to create a window using the following piece of code, the entire window is 640x480, with the window's chrome taking some of the client area:
HWND hWnd;
WNDCLASSEX WndClsEx;
ZeroMemory(&WndClsEx, sizeof(WNDCLASSEX));
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = DefWindowProc;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = TEXT("Title");
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&WndClsEx);
hWnd = CreateWindowEx( NULL,
TEXT("Title"),
TEXT("Title"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
假设简单的数学不会完全解决问题,
Assuming simple math won't quite solve the problem, how do I take the chrome size into account?
注意:我在创建窗口后使用SDL,
Note: I'm using SDL after creating the window, but I'm guessing it's bound to the window size and makes no difference to its size.
推荐答案
您可以使用AdjustWindowRect 或 AdjustWindowRectEx 函数计算给定所需客户区大小的窗口大小。
You can use the AdjustWindowRect or AdjustWindowRectEx function to calculate the window size given a desired client area size.
这篇关于WinAPI:创建一个具有指定客户区大小的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!