Drawing Rectangles

A rectangle is a four-sided polygon whose opposing sides are parallel and equal in length. Although an application can draw a rectangle by calling the Polygon function, supplying the coordinates of each corner, Windows provides a simpler method, use of the Rectangle function. This function requires only the coordinates for the upper left and the lower right corners. When an application calls the Rectangle function, Windows draws the rectangle, excluding the right and lower sides if no world transformation is set for the given device context.

If a world transformation has been set by using the SetWorldTransform or ModifyWorldTransform function, Windows includes the right and lower edges.

In addition to drawing a normal rectangle, the Microsoft® Win32® application programming interface (API) provides a function that applications can use to draw rectangles with rounded corners. This function, RoundRect, requires that the application supply the coordinates of the lower left and upper right corners, as well as the width and height of the ellipse used to round each corner.

The Win32 API also provides three functions that applications can use to manipulate rectangles, described as follows.

Function Description
FillRect Repaints the interior of a rectangle.
FrameRect Redraws the sides of a rectangle.
InvertRect Inverts the colors that appear within the interior of a rectangle.