Advertisement

Windows border size?

Started by January 07, 2001 02:14 PM
1 comment, last by Neelz0r 24 years ago
I''m just starting to learn windows programming (I already know C/C++ fairly well), and I started off by writing a program which displays the width, height, and coordinates of the window every time you move/resize it. So far it works perfectly, but I noticed that when you get the size or coordinates of the window, it doesn''t take into account the size of the window''s border. So how would I go about getting the border size? I tried just adding 8, which worked, but of course if somebody changes the border size in their windows settings, it''s off again. Thanks for helping - Neelz0r
The function you use to find this out is: GetSystemMetrics().

To find the border width:
      DWORD dwFrameWidth    = GetSystemMetrics( SM_CXSIZEFRAME );    

To find the border height:
  DWORD dwFrameHeight   = GetSystemMetrics( SM_CYSIZEFRAME );      

To find the menu height:
  DWORD dwMenuHeight    = GetSystemMetrics( SM_CYMENU );      

To find the caption height:
  DWORD dwCaptionHeight = GetSystemMetrics( SM_CYCAPTION );    

So, now to find the actual window width, you do:
  DWORD dwWindowWidth   = WINDOW_WIDTH  + dwFrameWidth * 2;      

To find the actual window height (take out the stuff you don't need if you dont have a menu, or caption)
  DWORD dwWindowHeight  = WINDOW_HEIGHT + dwFrameHeight * 2 +                         dwMenuHeight + dwCaptionHeight;    


Edited by - FrigidHelix on January 7, 2001 4:19:02 PM

Edited by - FrigidHelix on January 7, 2001 4:20:30 PM
Advertisement
A couple more ways to do this:

AdjustWindowRect will give you a window rectangle for a given client rectangle. You can use those to get widths/offsets, etc.

You can also use GetClientRect, which returns the client area''s rectangle relative to the window. (The window''s upper left corner is at (0, 0)).

Scott

This topic is closed to new replies.

Advertisement