Share via


CPoint::operator -

Use one of the first two overloads to subtract a CPoint or CSize object from CPoint.

CSize operator -( 
   POINT point  
) const throw( ); 
CPoint operator -( 
   SIZE size  
) const throw( ); 
CRect operator -( 
   const RECT* lpRect  
) const throw( ); 
CPoint operator -( ) const throw( );

Parameters

Return Value

A CSize that is the difference between two points, a CPoint that is offset by the negation of a size, a CRect that is offset by the negation of a point, or a CPoint that is the negation of a point.

Remarks

The third overload offsets a CRect by the negation of CPoint. Finally, use the unary operator to negate CPoint.

For example, using the first overload to find the difference between two points CPoint(25, -19) and CPoint(15, 5) returns CSize(10, -24).

Subtracting a CSize from CPoint does the same calculation as above but returns a CPoint object, not a CSize object. For example, using the second overload to find the difference between the point CPoint(25, -19) and the size CSize(15, 5) returns CPoint(10, -24).

Subtracting a rectangle from a point returns the rectangle offset by the negatives of the x and y values specified in the point. For example, using the last overload to offset the rectangle CRect(125, 200, 325, 400) by the point CPoint(25, -19) returns CRect(100, 219, 300, 419).

Use the unary operator to negate a point. For example, using the unary operator with the point CPoint(25, -19) returns CPoint(-25, 19).

Example

// example for CPoint subtraction
CPoint   ptStart(100, 100);
CSize   szOffset(35, 35);
CPoint   ptEnd;

ptEnd = ptStart - szOffset;

CPoint   ptResult(65, 65);

ASSERT(ptResult == ptEnd);

// also works on SIZE

ptStart = CPoint(100, 100);

SIZE   sz;
sz.cx = 35;
sz.cy = 35;

ptEnd = ptStart - sz;

ASSERT(ptResult == ptEnd);

// example for CPoint unary operator
CPoint   pt(35, 35);
pt = -pt;

CPoint ptNeg(-35, -35);
ASSERT(pt == ptNeg);   

Requirements

Header: atltypes.h

See Also

Reference

CPoint Class

Hierarchy Chart

CPoint::operator -=

CPoint::operator +=

CPoint::operator +

CSize::operator -

CRect::operator -

CPoint::Offset

CRect::OffsetRect

Other Resources

CPoint Members