Compartir a través de


CRect::SubtractRect

Makes the dimensions of the CRect equal to the subtraction of lpRectSrc2 from lpRectSrc1.

BOOL SubtractRect( 
   LPCRECT lpRectSrc1, 
   LPCRECT lpRectSrc2  
) throw( );

Parameters

  • lpRectSrc1
    Points to the RECT structure or CRect object from which a rectangle is to be subtracted.

  • lpRectSrc2
    Points to the RECT structure or CRect object that is to be subtracted from the rectangle pointed to by the lpRectSrc1 parameter.

Return Value

Nonzero if the function is successful; otherwise 0.

Remarks

The subtraction is the smallest rectangle that contains all of the points in lpRectScr1 that are not in the intersection of lpRectScr1 and lpRectScr2.

The rectangle specified by lpRectSrc1 will be unchanged if the rectangle specified by lpRectSrc2 doesn't completely overlap the rectangle specified by lpRectSrc1 in at least one of the x- or y-directions.

For example, if lpRectSrc1 were (10,10, 100,100) and lpRectSrc2 were (50,50, 150,150), the rectangle pointed to by lpRectSrc1 would be unchanged when the function returned. If lpRectSrc1 were (10,10, 100,100) and lpRectSrc2 were (50,10, 150,150), however, the rectangle pointed to by lpRectSrc1 would contain the coordinates (10,10, 50,100) when the function returned.

SubtractRect is not the same as operator - nor operator -=. Neither of these operators ever calls SubtractRect.

Nota

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

RECT   rectOne;
RECT   rectTwo;

rectOne.left = 10;
rectOne.top = 10;
rectOne.bottom = 100;
rectOne.right = 100;

rectTwo.left = 50;
rectTwo.top = 10;
rectTwo.bottom = 150;
rectTwo.right = 150;

CRect   rectDiff;

rectDiff.SubtractRect(&rectOne, &rectTwo);

CRect   rectResult(10, 10, 50, 100);

ASSERT(rectDiff == rectResult);

// works for CRect, too, since there is
// implicit CRect -> LPCRECT conversion

CRect rect1(10, 10, 100, 100);
CRect rect2(50, 10, 150, 150);
CRect rectOut;

rectOut.SubtractRect(rect1, rect2);
ASSERT(rectResult == rectOut);   

Requirements

Header: atltypes.h

See Also

Reference

CRect Class

Hierarchy Chart

CRect::operator -

CRect::operator -=

CRect::IntersectRect

CRect::UnionRect

CRect::NormalizeRect

SubtractRect

Other Resources

CRect Members