Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the size of the Non-client area of a Win32 window (native)

Tags:

c

winapi

How to set the size of the Non-client area of a Win32 window (native).

What I want is to make the CAPTION/TITLE bar THICKER.

I've read and been told that I should handle WM_NCCALCSIZE but I can't find nothing clear on the documentation.

From MSDN:

WM_NCCALCSIZE Notification


The WM_NCCALCSIZE message is sent when the size and position of a window's client area must be calculated. By processing this message, an application can control the content of the window's client area when the size or position of the window changes.

A window receives this message through its WindowProc function.

wParam If wParam is TRUE, it specifies that the application should indicate which part of the client area contains valid information. The system copies the valid information to the specified area within the new client area. If wParam is FALSE, the application does not need to indicate the valid part of the client area.

lParam If wParam is TRUE, lParam points to an NCCALCSIZE_PARAMS structure that contains information an application can use to calculate the new size and position of the client rectangle. If wParam is FALSE, lParam points to a RECT structure. On entry, the structure contains the proposed window rectangle for the window. On exit, the structure should contain the screen coordinates of the corresponding window client area.

like image 290
no_ripcord Avatar asked Jan 25 '10 19:01

no_ripcord


1 Answers

you set the size of the non-client area by handling the WM_NCCALCSIZE message. But don't do this unless you plan to do all of the non-client drawing as well by handling WM_NCPAINT

Edit: here are two code fragments, one that handles WM_NCCALCSIZE and provides a simple n pixel border, and another than adds some extra pixels after DefWindowProc has done the default handling.

case WM_NCCALCSIZE:
  {
  lRet = 0;
  const int cxBorder = 2;
  const int cyBorder = 2;
  InflateRect((LPRECT)lParam, -cxBorder, -cyBorder);
  }

case WM_NCCALCSIZE: 
  {
  LPNCCALCSIZE_PARAMS pncc = (LPNCCALCSIZE_PARAMS)lParam;
  //pncc->rgrc[0] is the new rectangle
  //pncc->rgrc[1] is the old rectangle
  //pncc->rgrc[2] is the client rectangle

  lRet = DefWindowProc (hwnd, WM_NCCALCSIZE, wParam, lParam);
  pncc->rgrc[0].top += ExtraCaptionHeight;
  }

You can learn a lot by passing WM_NCCALCSIZE to DefWindowProc and looking at the values of the NCCALCSIZEPARAM before and after.

like image 122
John Knoeller Avatar answered Nov 15 '22 18:11

John Knoeller