This documentation is archived and is not being maintained.

CRect Class 

Similar to a Windows RECT structure.

class CRect : public tagRECT

CRect also includes member functions to manipulate CRect objects and Windows RECT structures.

A CRect object can be passed as a function parameter wherever a RECT structure, LPCRECT, or LPRECT can be passed.


This class is derived from the tagRECT structure. (The name tagRECT is a less-commonly-used name for the RECT structure.) This means that the data members (left, top, right, and bottom) of the RECT structure are accessible data members of CRect.

A CRect contains member variables that define the top-left and bottom-right points of a rectangle.

When specifying a CRect, you must be careful to construct it so that it is normalized — in other words, such that the value of the left coordinate is less than the right and the top is less than the bottom. For example, a top left of (10,10) and bottom right of (20,20) defines a normalized rectangle but a top left of (20,20) and bottom right of (10,10) defines a non-normalized rectangle. If the rectangle is not normalized, many CRect member functions may return incorrect results. (See CRect::NormalizeRect for a list of these functions.) Before you call a function that requires normalized rectangles, you can normalize non-normalized rectangles by calling the NormalizeRect function.

Use caution when manipulating a CRect with the CDC::DPtoLP and CDC::LPtoDP member functions. If the mapping mode of a display context is such that the y-extent is negative, as in MM_LOENGLISH, then CDC::DPtoLP will transform the CRect so that its top is greater than the bottom. Functions such as Height and Size will then return negative values for the height of the transformed CRect, and the rectangle will be non-normalized.

When using overloaded CRect operators, the first operand must be a CRect; the second can be either a RECT structure or a CRect object.


For more information on shared utility classes (like CRect), see Shared Classes.

Header: atltypes.h

This class is not supported in Smart Device projects.