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?

1
  • Have you tried looking at functions in the Visual Styles (aka Themes) API? eg. GetThemeMetric() Commented Feb 5, 2014 at 5:00

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, but I believe that the following answer is more accurate, and also is easier to work with DPI: stackoverflow.com/a/28524464/2604492
Notwithstanding the previous comment (which should supersede this), the *2 should be applied to both terms (parenthesis are in the wrong place).
5

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.

Comments

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;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.