::GetSystemMetrics (SM_CYBORDER)
...返回 1,我知道标题栏比 ONE 像素高:/
我也试过了:
RECT r; r.left = r.top = 0; r.right = r.bottom = 400; ::AdjustWindowRect (& r, WS_OVERLAPPED, FALSE); _bdW = (uword)(r.right - r.left - 400); _bdH = (uword)(r.bottom - r.top - 400);
但是边框 w,h 回来为 0。
在我的 WM_SIZE 处理程序中,我需要确保窗口的高度在 “步骤”,例如,一个全新的文本行可以适合窗口 底部没有“垃圾部分行空间”。
但是::MoveWindow 需要添加边框空间的尺寸。
之前一定有人这样做过... 感谢您的帮助:)
最佳答案
GetWindowRect和 GetClientRect函数可用于计算所有窗口边框的大小。
Suite101 有一篇关于 resizing a window and the keeping client area at a know size 的文章.
这是他们的示例代码:
void ClientResize(HWND hWnd, int nWidth, int nHeight)
{
RECT rcClient, rcWind;
POINT ptDiff;
GetClientRect(hWnd, &rcClient);
GetWindowRect(hWnd, &rcWind);
ptDiff.x = (rcWind.right - rcWind.left) - rcClient.right;
ptDiff.y = (rcWind.bottom - rcWind.top) - rcClient.bottom;
MoveWindow(hWnd,rcWind.left, rcWind.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE);
}
关于c++ - Win32中的窗口边框宽度和高度 - 我如何获得它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/431470/