How to get the default caption bar height of a window in Windows?
win32gui, winapi, windows
Solution
Source code ported from Firefox:
// mCaptionHeight is the default size of the NC area at
// the top of the window. If the window has a caption,
// the size is calculated as the sum of:
// SM_CYFRAME - The thickness of the sizing border
// around a resizable window
// SM_CXPADDEDBORDER - The amount of border padding
// for captioned windows
// SM_CYCAPTION - The height of the caption area
//
// If the window does not have a caption, mCaptionHeight will be equal to
// `GetSystemMetrics(SM_CYFRAME)`
int height = (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION) +
GetSystemMetrics(SM_CXPADDEDBORDER));
return height;
PS: the height is dpi-dependent.
Problem
I am developing an application which employs a self-drawn titlebar, which needs to mimic the system default titlebar. So how could I get the default titlebar height of an overloapped window in Windows?