IntersectClipRect

2.x

  int IntersectClipRect(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect)    
  HDC hdc; /* handle of device context */
  int nLeftRect; /* x-coordinate top-left corner of rectangle */
  int nTopRect; /* y-coordinate top-left corner of rectangle */
  int nRightRect; /* x-coordinate bottom-right corner of rectangle */
  int nBottomRect; /* y-coordinate bottom-right corner of rectangle */

The IntersectClipRect function creates a new clipping region from the intersection of the current region and a specified rectangle.

Parameters

hdc

Identifies the device context.

nLeftRect

Specifies the logical x-coordinate of the upper-left corner of the rectangle.

nTopRect

Specifies the logical y-coordinate of the upper-left corner of the rectangle.

nRightRect

Specifies the logical x-coordinate of the lower-right corner of the rectangle.

nBottomRect

Specifies the logical y-coordinate of the lower-right corner of the rectangle.

Return Value

The return value specifies that the resulting region has overlapping borders (COMPLEXREGION), is empty (NULLREGION), or has no overlapping borders (SIMPLEREGION). Otherwise, the return value is ERROR.

Comments

An application uses the IntersectClipRect function to create a clipping region from the intersection of the current region and a specified rectangle. An application can also create a clipping region that is the intersection of two regions, by specifying RGN_AND in a call to the CombineRgn function and then making this combined region the clipping region by calling the SelectClipRgn function.

The width of the rectangle, specified by the absolute value of nRightRectnLeftRect, must not exceed 32,767 units. This limit applies to the height of the rectangle as well.

Example

The following example creates a square clipping region and colors it red by using a red brush to fill the client area. The IntersectClipRect function is called with coordinates that overlap the region, and the client area is filled with a yellow brush. The only region colored yellow is the overlap between the region and the coordinates specified in the call to IntersectClipRect.

RECT rc;
HRGN hrgn;
HBRUSH hbrRed, hbrYellow;

GetClientRect(hwnd, &rc);
hrgn = CreateRectRgn(10, 10, 110, 110);
SelectClipRgn(hdc, hrgn);
hbrRed = CreateSolidBrush(RGB(255, 0, 0));
FillRect(hdc, &rc, hbrRed);

IntersectClipRect(hdc, 100, 100, 200, 200);

hbrYellow = CreateSolidBrush(RGB(255, 255, 0));
FillRect(hdc, &rc, hbrYellow);

DeleteObject(hbrRed);
DeleteObject(hbrYellow);
DeleteObject(hrgn);

See Also

CombineRgn, SelectClipRgn