::GetSystemMetrics (SM_CYBORDER)
...回来1,我知道标题栏高于一个像素:/
我也尝试过:
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处理程序中,我需要确保窗口的高度在"步骤"中变化,因此,例如,一个全新的文本行可以放在窗口中,底部没有"junky partial line space".
但是:: MoveWindow需要添加边框空间的尺寸.
有人必须在此之前完成此任务...感谢您的帮助:)
stu*_*lly 39
该GetWindowRect和GetClientRect函数可用于计算所有窗口边框的大小.
Suite101有一篇关于调整窗口大小和保持客户区域大小的文章.
这是他们的示例代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
小智 12
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
Run Code Online (Sandbox Code Playgroud)
事实上,上述结果等于:
GetClientRect(hWnd, &rcClient);
GetWindowRect(hWnd, &rcWind);
int border_thickness = ((rcWind.right - rcWind.left) - rcClient.right) / 2;
Run Code Online (Sandbox Code Playgroud)
但"GetSystemMetrics(SM_CXSIZEFRAME)"很容易使用.
小智 5
除非窗口最小化或未完全初始化,否则 Stukelly 建议的方法将起作用。在这些条件下为您提供边框大小的另一种方法是使用该AdjustWindowRectEx函数。这是一个例子:
CSize GetBorderSize(const CWnd& window)
{
// Determine the border size by asking windows to calculate the window rect
// required for a client rect with a width and height of 0
CRect rect;
AdjustWindowRectEx(&rect, window.GetStyle(), FALSE, window.GetExStyle());
return rect.Size();
}
Run Code Online (Sandbox Code Playgroud)
根据应用程序的不同,如果需要当前可见边框大小,则可能需要将此方法与 Stukelly 的方法结合起来:
CSize GetBorderSize(const CWnd& window)
{
if (window.IsZoomed())
{
// The total border size is found by subtracting the size of the client rect
// from the size of the window rect. Note that when the window is zoomed, the
// borders are hidden, but the title bar is not.
CRect wndRect, clientRect;
window.GetWindowRect(&wndRect);
window.GetClientRect(&clientRect);
return wndRect.Size() - clientRect.Size();
}
else
{
// Determine the border size by asking windows to calculate the window rect
// required for a client rect with a width and height of 0. This method will
// work before the window is fully initialized and when the window is minimized.
CRect rect;
AdjustWindowRectEx(&rect, window.GetStyle(), FALSE, window.GetExStyle());
return rect.Size();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53829 次 |
| 最近记录: |