窗口边框的宽度和高度在Win32 - 我该如何得到它? [英] window border width and height in Win32 - how do I get it?
问题描述
::GetSystemMetrics (SM_CYBORDER)
...回到1,我知道标题bar高于ONE像素:/
...comes back with 1 and I know the title bar is taller than ONE pixel :/
我也尝试过:
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.
But border w,h came back as 0.
在我的WM_SIZE处理程序,我需要确保窗口的高度在
steps中改变,因此,例如一个整行的文本可以适合窗口
,在底部没有垃圾部分行间距。
In my WM_SIZE handler, I need to make sure the window's height changes in "steps" so, for example a whole new line of text could fit in the window with no "junky partial line space" at the bottom.
但是:: MoveWindow需要添加边框空间的尺寸。
But ::MoveWindow needs the dimensions WITH the border space added in.
...
感谢任何帮助:)
SOMEbody must have done this before... Thanks for any help :)
推荐答案
GetWindowRect 和 GetClientRect 函数可以计算所有窗口边框的大小。
The GetWindowRect and GetClientRect functions can be used calculate the size of all the window borders.
Suite101有一篇关于调整窗口大小和保持客户区域已知大小的文章。
Suite101 has a article on 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);
}
这篇关于窗口边框的宽度和高度在Win32 - 我该如何得到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!