次の方法で共有


CRect Class

Similar to a Windows RECT structure.

class CRect : public tagRECT

Members

Public Constructors

Name

Description

CRect::CRect

Constructs a CRect object.

Public Methods

Name

Description

CRect::BottomRight

Returns the bottom-right point of CRect.

CRect::CenterPoint

Returns the centerpoint of CRect.

CRect::CopyRect

Copies the dimensions of a source rectangle to CRect.

CRect::DeflateRect

Decreases the width and height of CRect.

CRect::EqualRect

Determines whether CRect is equal to the given rectangle.

CRect::Height

Calculates the height of CRect.

CRect::InflateRect

Increases the width and height of CRect.

CRect::IntersectRect

Sets CRect equal to the intersection of two rectangles.

CRect::IsRectEmpty

Determines whether CRect is empty. CRect is empty if the width and/or height are 0.

CRect::IsRectNull

Determines whether the top, bottom, left, and right member variables are all equal to 0.

CRect::MoveToX

Moves CRect to the specified x-coordinate.

CRect::MoveToXY

Moves CRect to the specified x- and y-coordinates.

CRect::MoveToY

Moves CRect to the specified y-coordinate.

CRect::NormalizeRect

Standardizes the height and width of CRect.

CRect::OffsetRect

Moves CRect by the specified offsets.

CRect::PtInRect

Determines whether the specified point lies within CRect.

CRect::SetRect

Sets the dimensions of CRect.

CRect::SetRectEmpty

Sets CRect to an empty rectangle (all coordinates equal to 0).

CRect::Size

Calculates the size of CRect.

CRect::SubtractRect

Subtracts one rectangle from another.

CRect::TopLeft

Returns the top-left point of CRect.

CRect::UnionRect

Sets CRect equal to the union of two rectangles.

CRect::Width

Calculates the width of CRect.

Public Operators

Name

Description

CRect::operator -

Subtracts the given offsets from CRect or deflates CRect and returns the resulting CRect.

CRect::operator LPCRECT

Converts a CRect to an LPCRECT.

CRect::operator LPRECT

Converts a CRect to an LPRECT.

CRect::operator !=

Determines whether CRect is not equal to a rectangle.

CRect::operator &

Creates the intersection of CRect and a rectangle and returns the resulting CRect.

CRect::operator &=

Sets CRect equal to the intersection of CRect and a rectangle.

CRect::operator |

Creates the union of CRect and a rectangle and returns the resulting CRect.

CRect::operator |=

Sets CRect equal to the union of CRect and a rectangle.

CRect::operator +

Adds the given offsets to CRect or inflates CRect and returns the resulting CRect.

CRect::operator +=

Adds the specified offsets to CRect or inflates CRect.

CRect::operator =

Copies the dimensions of a rectangle to CRect.

CRect::operator -=

Subtracts the specified offsets from CRect or deflates CRect.

CRect::operator ==

Determines whether CRect is equal to a rectangle.

Remarks

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.

Note

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.

Note

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

Inheritance Hierarchy

tagRECT

CRect

Requirements

Header: atltypes.h

See Also

Reference

Hierarchy Chart

CPoint Class

CSize Class

RECT Structure