7

I am using GetSystemMetrics(SM_CXSIZEFRAME) for the width of the border, it works with the basic design, but not with aero, how can I improve it, so it works with aero?

I am using GetSystemMetrics(SM_CYCAPTION) for the height of the title bar but the value is too small for both, basic and aero design, what am I doing wrong here?

TLama
  • 75,147
  • 17
  • 214
  • 392
Alph0r
  • 199
  • 1
  • 9

3 Answers3

10

In unthemed Windows, GetSystemMetrics(SM_CYCAPTION) is the height of the text in the title bar; you need to add in the size of the frame and border padding (GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYEDGE) * 2).

For themed Windows (which is the default these days), GetThemeSysSize is most likely the function you're looking for; in particular, GetThemeSysSize(SM_CXBORDER) for the border width, and GetThemeSysSize(SM_CYSIZE) + GetThemeSysSize(SM_CXPADDEDBORDER) * 2 for the title bar.

Eric Brown
  • 13,774
  • 7
  • 30
  • 71
  • Thank you, but I believe that the following answer is more accurate, and also is easier to work with DPI: https://stackoverflow.com/a/28524464/2604492 – Paul Sep 04 '21 at 16:33
4

I had a similar problem, where I needed to subtract the title bar height from the mouse Y to render a cursor in the window.

After looking around, and looking at functions like GetSystemMetrics, I ended up just using GetWindowRect and ClientToScreen.

I got the screen position of the client area using ClientToScreen with point 0,0. Then subtracted that from the window top retrieved through GetWindowRect. Result is the distance from the top of the window to the inside of the window. Or the titlebar height.

MulleDK19
  • 197
  • 1
  • 4
0
int getWindowHeadSize()
{
    RECT Rect;
    GetWindowRect(hWnd, &Rect);
    POINT point = { 0, 0 };
    ClientToScreen(hWnd, &point);
    return point.y - Rect.top + GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYEDGE) * 2;
}