Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C++
ATL/MFC
CRect Class
 CRect::SubtractRect

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Shared Visual C++ Classes Reference
CRect::SubtractRect

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

BOOL SubtractRect( 
   LPCRECT lpRectSrc1, 
   LPCRECT lpRectSrc2  
) throw( );
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.

Nonzero if the function is successful; otherwise 0.

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.

NoteNote:

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

Visual C++
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);   

Header: atltypes.h

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker