由stukelly建议的方法将工作,除非窗口最小化或未完全initialzied。在这些条件下给出边界大小的另一种方法是使用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();
}
根据应用的不同,它可能是必要的,如果当前可见的边框尺寸是必要的这一做法与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();
}
}
对于文档`AdjustWindowRect`说,相当无益,你不能使用`WS_OVERLAPPED`。 – JWWalker 2012-02-01 20:31:04
@JWWalker:其实这很有帮助。现在,如果你也知道'WS_OVERLAPPED'被定义为'0x0',它应该很明显,为什么。 – IInspectable 2017-11-15 22:34:39
@IInspectable,不,我不知道为什么WS_OVERLAPPED是0是相关的。 – JWWalker 2017-11-16 16:19:39