Share via


CRect::IntersectRect

BOOLIntersectRect(LPCRECTlpRect1**,LPCRECTlpRect2);**

Return Value

Nonzero if the intersection is not empty; 0 if the intersection is empty.

Parameters

lpRect1

Points to a RECT structure or CRect object that contains a source rectangle.

lpRect2

Points to a RECT structure or CRect object that contains a source rectangle.

Remarks

Makes a CRect equal to the intersection of two existing rectangles. The intersection is the largest rectangle contained in both existing rectangles.

Note   Both of the rectangles must be normalized or this function may fail. You can call NormalizeRect to normalize the rectangles before calling this function.

Example

CRect rectOne(125,   0, 150, 200);
CRect rectTwo(  0,  75, 350,  95);
CRect rectInter;

rectInter.IntersectRect(rectOne, rectTwo);

// rectInter is now (125, 75, 150, 95)

ASSERT(rectInter == CRect(125, 75, 150, 95));

// operator &= can do the same task:

CRect rectInter2 = rectOne;
rectInter2 &= rectTwo;
ASSERT(rectInter2 == CRect(125, 75, 150, 95));

CRect OverviewClass MembersHierarchy Chart

See Also   CRect::operator &=, CRect::operator &, CRect::UnionRect, CRect::SubtractRect, CRect::NormalizeRect,