Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

winapi

       ::GetSystemMetrics (SM_CYBORDER) 

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

I also tried:

      RECT r;       r.left = r.top = 0;   r.right = r.bottom = 400;       ::AdjustWindowRect (& r, WS_OVERLAPPED, FALSE);       _bdW = (uword)(r.right - r.left - 400);       _bdH = (uword)(r.bottom - r.top - 400); 

But border w,h came back as 0.

In my WM_SIZE handler, I need to make sure the window's height changes in "steps" so, for example a whole new line of text could fit in the window with no "junky partial line space" at the bottom.

But ::MoveWindow needs the dimensions WITH the border space added in.

SOMEbody must have done this before... Thanks for any help :)

like image 588
Stephen Hazel Avatar asked Jan 10 '09 18:01

Stephen Hazel


People also ask

How do you change window border size?

First, open the Registry Editor by pressing the Windows key, typing regedit, and pressing Enter. To make your window borders as small as possible, double-click BorderWidth and set it to 0, and then double-click PaddedBoderWidth and set it to 0. Sign out and sign back in to activate your new window border width.

How do I change the border size in Windows 10?

Change thickness or width of the window borders To begin with, double-click on BorderWidth and change its value to say, 0. This value determines the current setting for the width of the borders around all the windows with borders that can be sized.


1 Answers

The GetWindowRect and GetClientRect functions can be used calculate the size of all the window borders.

Suite101 has a article on resizing a window and the keeping client area at a know size.

Here is their sample code:

void ClientResize(HWND hWnd, int nWidth, int nHeight) {   RECT rcClient, rcWind;   POINT ptDiff;   GetClientRect(hWnd, &rcClient);   GetWindowRect(hWnd, &rcWind);   ptDiff.x = (rcWind.right - rcWind.left) - rcClient.right;   ptDiff.y = (rcWind.bottom - rcWind.top) - rcClient.bottom;   MoveWindow(hWnd,rcWind.left, rcWind.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE); } 
like image 86
stukelly Avatar answered Sep 20 '22 12:09

stukelly