The method suggested by stukelly will work unless the window is minimized or not fully initialzied. An alternate approach that will give you the border size in these conditions is to use the AdjustWindowRectEx
function. Here is an example:
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();
}
Depending on the application, it may be necessary to combine this approach with stukelly's if the current visible border size is necessary:
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();
}
}