Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
799 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...