1.18.3 Creating and Manipulating Rectangles

The SetRect function creates a rectangle, the CopyRect function makes a copy of a given rectangle, and the SetRectEmpty function creates an empty rectangle. An empty rectangle is any rectangle that has zero width, zero height, or both.

The InflateRect function increases or decreases the width and height of a rectangle. It adds or removes width from both ends of the rectangle, or adds or removes height from both the top and bottom of the rectangle.

The OffsetRect function moves the rectangle by a given amount. It moves the corners of the rectangle by adding the given x and y amounts to the corner coordinates.

The PtInRect function determines whether a given point lies within a given rectangle. The point is in the rectangle if it lies on the left or top side or is completely within the rectangle.

The IsRectEmpty function determines whether the given rectangle is empty.

The IntersectRect function creates a new rectangle that is the intersection of two existing rectangles. The intersection is the largest rectangle contained in both existing rectangles. The intersection of two rectangles is shown in Figure 1.4:

The UnionRect function creates a new rectangle that is the union of two existing rectangles. The union is the smallest rectangle that contains both existing rectangles. The union of two rectangles is shown in Figure 1.5:

For information about functions that draw ellipses and polygons, see Section 2.10, “Ellipse and Polygon Functions.”