WM_NCCALCSIZE

2.x

WM_NCCALCSIZE
fCalcValidRects = (BOOL) wParam;            /* valid-area flag  */
lpncsp = (NCCALCSIZE_PARAMS FAR*) lParam;   /* address of data  */

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

Parameters

fCalcValidRects

Value of wParam. Specifies whether the application should specify which part of the client area contains valid information. Windows will copy the valid information to the specified area within the new client area. If this parameter is TRUE, the application should specify which part of the client area is valid.

lpncsp

Value of lParam. Points to an NCCALCSIZE_PARAMS data structure that contains information an application can use to calculate the new size and position of the client rectangle. The NCCALCSIZE_PARAMS structure has the following form:

typedef struct tagNCCALCSIZE_PARAMS {
    RECT           rgrc[3];
    WINDOWPOS FAR* lppos;
} NCCALCSIZE_PARAMS;

Regardless of the value of fCalcValidRects, the first rectangle in the array specified by the rgrc member contains the coordinates of the window. For a child window, the coordinates are relative to the parent window's client area. For top-level windows, the coordinates are screen coordinates. An application should process WM_NCCALCSIZE by modifying the rgrc[0] rectangle to reflect the size and position of the client area.

The rgrc[1] and rgrc[2] rectangles are valid only if fCalcValidRects is TRUE. In this case, the rgrc[1] rectangle contains the coordinates of the window before it was moved or resized. The rgrc[2] rectangle contains the coordinates of the window's client area before the window was moved. All coordinates are relative to the parent window or screen.

Return Value

An application should return zero if fCalcValidRects is FALSE.

An application can return zero or a valid combination of the following values if fCalcValidRects is TRUE:

Value Meaning

WVR_ALIGNTOP, WVR_ALIGNLEFT, WVR_ALIGNBOTTOM, WVR_ALIGNRIGHT, These values, used in combination, specify that the client area of the window is to be preserved and aligned appropriately relative to the new location of the client window. For example, to align the client area to the lower-left, return WVR_ALIGNLEFT | WVR_ALIGNTOP.  
WVR_HREDRAW, WVR_VREDRAW These values, used in combination with any other values, cause the window to be completely redrawn if the client rectangle changed size horizontally or vertically. These values are similar to the CS_HREDRAW and CS_VREDRAW class styles.
WVR_REDRAW This value causes the entire window to be redrawn. It is a combination of WVR_HREDRAW and WVR_VREDRAW.
WVR_VALIDRECTS This value indicates that, upon return from WM_NCCALCSIZE, the rgrc[1] and rgrc[2] rectangles contain valid source and destination area rectangles, respectively. Windows combines these rectangles to calculate the area of the window that can be preserved. Windows copies any part of the window image that is within the source rectangle and clips the image to the destination rectangle. Both rectangles are in parent-relative or screen-relative coordinates.
  This return value allows an application to implement more elaborate client-area preservation strategies, such as centering or preserving a subset of the client area.

If fCalcValidRects is TRUE and an application returns zero, the old client area is preserved and is aligned with the upper-left corner of the new client area.

Comments

Redrawing of the window may occur, depending on whether CS_HREDRAW or CS_VREDRAW was specified. This is the default, backward-compatible DefWindowProc processing of this message (in addition to the usual client rectangle calculation described in the preceding table).

See Also

DefWindowProc, MoveWindow, SetWindowPos