由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