window border width and height in Win32 - how do I get it?

前端 未结 6 925
慢半拍i
慢半拍i 2020-12-08 10:10
      ::GetSystemMetrics (SM_CYBORDER)

...comes back with 1 and I know the title bar is taller than ONE pixel :/

I also tried:

     RECT r;
         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 10:40

    You have another solution... You can pre calculate the border by calling a dedicated function while in WM_CREATE and WM_INITDIALOG messages. And refresh the values when you change your window style or when menu split in two rows.

    RECT cRect, wRect, oRect;
    GetWindowRect(hWnd, &wRect);
    GetClientRect(hWnd, &cRect);
    MapWindowPoints(hWnd, NULL, (LPPOINT)&cRect, 2);
    
    oRect.left = cRect.left - wRect.left;
    oRect.top = cRect.top - wRect.top;
    oRect.right = wRect.right - cRect.right;
    oRect.bottom = wRect.bottom - cRect.bottom;
    

提交回复
热议问题