Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Similar to the Windows SIZE structure, which implements a relative coordinate or position.
Syntax
class CSize : public tagSIZE
Members
Public Constructors
| Name | Description |
|---|---|
| CSize::CSize | Constructs a CSize object. |
Public Operators
| Name | Description |
|---|---|
| CSize::operator - | Subtracts two sizes. |
| CSize::operator != | Checks for inequality between CSize and a size. |
| CSize::operator + | Adds two sizes. |
| CSize::operator += | Adds a size to CSize. |
| CSize::operator -= | Subtracts a size from CSize. |
| CSize::operator == | Checks for equality between CSize and a size. |
Remarks
This class is derived from the SIZE structure. This means you can pass a CSize in a parameter that calls for a SIZE and that the data members of the SIZE structure are accessible data members of CSize.
The cx and cy members of SIZE (and CSize) are public. In addition, CSize implements member functions to manipulate the SIZE structure.
Note
For more information on shared utility classes (like CSize), see Shared Classes.
Inheritance Hierarchy
tagSIZE
CSize
Requirements
Header: atltypes.h
CSize::CSize
Constructs a CSize object.
CSize() throw();
CSize( int initCX, int initCY) throw();
CSize( SIZE initSize) throw();
CSize( POINT initPt) throw();
CSize( DWORD dwSize) throw();
Parameters
initCX
Sets the cx member for the CSize.
initCY
Sets the cy member for the CSize.
initSize
SIZE structure or CSize object used to initialize CSize.
initPt
POINT structure or CPoint object used to initialize CSize.
dwSize
DWORD used to initialize CSize. The low-order word is the cx member and the high-order word is the cy member.
Remarks
If no arguments are given, cx and cy are initialized to zero.
Example
CSize szEmpty;
CSize szPointA(10, 25);
SIZE sz;
sz.cx = 10;
sz.cy = 25;
CSize szPointB(sz);
POINT pt;
pt.x = 10;
pt.y = 25;
CSize szPointC(pt);
CPoint ptObject(10, 25);
CSize szPointD(ptObject);
DWORD dw = MAKELONG(10, 25);
CSize szPointE(dw);
ASSERT(szPointA == szPointB);
ASSERT(szPointB == szPointC);
ASSERT(szPointC == szPointD);
ASSERT(szPointD == szPointE);
CSize::operator ==
Checks for equality between two sizes.
BOOL operator==(SIZE size) const throw();
Remarks
Returns nonzero if the sizes are equal, otherwise 0.
Example
CSize sz1(135, 135);
CSize sz2(135, 135);
ASSERT(sz1 == sz2);
CSize::operator !=
Checks for inequality between two sizes.
BOOL operator!=(SIZE size) const throw();
Remarks
Returns nonzero if the sizes are not equal, otherwise 0.
Example
CSize sz1(222, 222);
CSize sz2(111, 111);
ASSERT(sz1 != sz2);
CSize::operator +=
Adds a size to this CSize.
void operator+=(SIZE size) throw();
Example
CSize sz1(100, 100);
CSize sz2(50, 25);
sz1 += sz2;
CSize szResult(150, 125);
ASSERT(sz1 == szResult);
// works with SIZE, too
sz1 = CSize(100, 100);
SIZE sz3;
sz3.cx = 50;
sz3.cy = 25;
sz1 += sz3;
ASSERT(sz1 == szResult);
CSize::operator -=
Subtracts a size from this CSize.
void operator-=(SIZE size) throw();
Example
CSize sz1(100, 100);
CSize sz2(50, 25);
sz1 -= sz2;
CSize szResult(50, 75);
ASSERT(sz1 == szResult);
// works with SIZE, too
sz1 = CSize(100, 100);
SIZE sz3;
sz3.cx = 50;
sz3.cy = 25;
sz1 -= sz3;
ASSERT(sz1 == szResult);
CSize::operator +
These operators add this CSize value to the value of parameter.
CSize operator+(SIZE size) const throw();
CPoint operator+(POINT point) const throw();
CRect operator+(const RECT* lpRect) const throw();
Remarks
See the following descriptions of the individual operators:
operator +( size )
This operation adds two
CSizevalues.operator +( point )
This operation offsets (moves) a POINT (or CPoint) value by this
CSizevalue. Thecxandcymembers of thisCSizevalue are added to thexandydata members of thePOINTvalue. It is analogous to the version of CPoint::operator + that takes a SIZE parameter.operator +( lpRect )
This operation offsets (moves) a RECT (or CRect) value by this
CSizevalue. Thecxandcymembers of thisCSizevalue are added to theleft,top,right, andbottomdata members of theRECTvalue. It is analogous to the version of CRect::operator + that takes a SIZE parameter.
Example
CSize sz1(100, 100);
CSize sz2(50, 25);
CSize szOut;
szOut = sz1 + sz2;
CSize szResult(150, 125);
ASSERT(szOut == szResult);
// works with SIZE, too
sz1 = CSize(100, 100);
SIZE sz3;
sz3.cx = 50;
sz3.cy = 25;
szOut = sz1 + sz3;
ASSERT(szOut == szResult);
CSize::operator -
The first three of these operators subtract this CSize value to the value of parameter.
CSize operator-(SIZE size) const throw();
CPoint operator-(POINT point) const throw();
CRect operator-(const RECT* lpRect) const throw();
CSize operator-() const throw();
Remarks
The fourth operator, the unary minus, changes the sign of the CSize value. See the following descriptions of the individual operators:
operator -( size )
This operation subtracts two
CSizevalues.operator -( point )
This operation offsets (moves) a POINT or CPoint value by the additive inverse of this
CSizevalue. Thecxandcyof thisCSizevalue are subtracted from thexandydata members of thePOINTvalue. It is analogous to the version of CPoint::operator - that takes a SIZE parameter.operator -( lpRect )
This operation offsets (moves) a RECT or CRect value by the additive inverse of this
CSizevalue. Thecxandcymembers of thisCSizevalue are subtracted from theleft,top,right, andbottomdata members of theRECTvalue. It is analogous to the version of CRect::operator - that takes a SIZE parameter.operator -()
This operation returns the additive inverse of this
CSizevalue.
Example
CSize sz1(100, 100);
CSize sz2(50, 25);
CSize szOut;
szOut = sz1 - sz2;
CSize szResult(50, 75);
ASSERT(szOut == szResult);
// works with SIZE, too
sz1 = CSize(100, 100);
SIZE sz3;
sz3.cx = 50;
sz3.cy = 25;
szOut = sz1 - sz3;
ASSERT(szOut == szResult);