Table of contents
1.
Introduction 
2.
Active Template Library
3.
UtilityClass-CSize
3.1.
Syntax
4.
Members
4.1.
Public Constructors
4.2.
Public Operators
5.
CSize::CSize
5.1.
Parameters
5.2.
Example
6.
CSize::operator ==
6.1.
Example
7.
CSize::operator !=
7.1.
Example
8.
CSize::operator +=
8.1.
Example
9.
CSize::operator -=
9.1.
Example
10.
CSize::operator +
10.1.
Example
11.
CSize::operator -
11.1.
Example
12.
Frequently Asked Questions
12.1.
What CSize Class does?
12.2.
What is the use of the SIZE structure?
12.3.
What is ATL?
13.
Conclusion
Last Updated: Mar 27, 2024
Medium

UtilityClass-CSize

Author Shiva
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 

Hello, readers. In this article, we will learn about UtilityClass-CSize. It is one of the several classes provided by Active Template Library. We’ll briefly cover ATL, about CSize class, its syntax, and its members. We’ll also discuss why we use it.

utilityclass csize

Active Template Library

The Active Template Library (ATL) is a collection of template-based C++ classes that allow you to create small, quick COM(Component Object Model) objects. It supports major COM features such as standard COM enumerator interfaces, stock implementations, dual interfaces, tear-off interfaces, connection points, and ActiveX controls.

UtilityClass-CSize

This class is derived from the SIZE structure. As a result, you can send a CSize as a parameter when a SIZE is required, and the data members of the SIZE structure are also available for use with CSize. The SIZE structure defines the width and height of a rectangle. We use windef.h header file to use it. 

The SIZE (and CSize) cx and cy members are open to the public. In order to modify the SIZE structure, CSize also implements member functions.

Syntax

#include<atltypes.h>
class CSize : public tagSIZE

Header file atltypes.h is required.

Members

Public Constructors

Name Description
CSize::CSize CSize object is built.

Public Operators

Name Description
CSize::operator - It subtracts two sizes.
CSize::operator != It will check for inequality between CSize and size.
CSize::operator + It will add two sizes given.
CSize::operator += It will add a size to CSize.
CSize::operator -= It reduces the size from the CSize.
CSize::operator == It will checks to see whether CSize and size are the same.

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

Name

Description

initCX Sets the CSize's cx member.
initCY CSize's cy member is set.
initCSize Used to initialize CSize is the initSize SIZE structure or CSize object.
initPt CSize is initialized using the initPt POINT structure or CPoint object.
dwSize CSize was set up using the DWORD dwSize. The cx member is a low-order word, whereas the cy member is a high-order word.

Note: cx and cy are initialized to zero if no arguments are provided.

Example

CSize szEmpty;
CSize szPointA(2, 5);

SIZE sz;
sz.cx = 2;
sz.cy = 5;
CSize szPointB(sz);

POINT pt;
pt.x = 2;
pt.y = 5;
CSize szPointC(pt);

CPoint ptObject(2, 5);
CSize szPointD(ptObject);   

DWORD dw = MAKELONG(2, 5);
CSize szPointE(dw);

ASSERT(szPointA == szPointB);
ASSERT(szPointB == szPointC);
ASSERT(szPointC == szPointD);
ASSERT(szPointD == szPointE);

CSize::operator ==

It checks for equality between the two sizes.

BOOL operator==(SIZE size) const throw();
/* If the sizes are equal, then it returns nonzero, otherwise 0.*/

Example

CSize sz1(100, 100);
CSize sz2(100, 100);

ASSERT(sz1 == sz2);
You can also try this code with Online C++ Compiler
Run Code

CSize::operator !=

It checks for inequality between the two sizes.

BOOL operator!=(SIZE size) const throw();
/* If the sizes are not equal, then it returns nonzero, otherwise 0.*/

Example

CSize sz1(88, 88);
CSize sz2(44, 44);

ASSERT(sz1 != sz2);   
You can also try this code with Online C++ Compiler
Run Code

CSize::operator +=

It adds size to this CSize.

void operator+=(SIZE size) throw();

Example

CSize sz1(20, 20);
CSize sz2(10,  5);
sz1 += sz2;

CSize szResult(30, 25);
ASSERT(sz1 == szResult);

/* It works with SIZE, too */

sz1 = CSize(20, 20);
SIZE sz3;
sz3.cx = 10;
sz3.cy = 5;

sz1 += sz3;
ASSERT(sz1 == szResult);   
You can also try this code with Online C++ Compiler
Run Code

CSize::operator -=

It subtracts a size from this CSize.

void operator-=(SIZE size) throw();

Example

CSize sz1(20, 20);
CSize sz2(10,  5);

sz1 -= sz2;

CSize szResult(10, 15);
ASSERT(sz1 == szResult);

/* It works with SIZE, too */

sz1 = CSize(20, 20);
SIZE sz3;
sz3.cx = 10;
sz3.cy = 5;

sz1 -= sz3;
ASSERT(sz1 == szResult);   
You can also try this code with Online C++ Compiler
Run Code

CSize::operator +

These operators add this CSize value to the value of the parameter.

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

Example

CSize sz1(20, 20);
CSize sz2(10,  5);
CSize szOutput;

szOutput = sz1 + sz2;

CSize szResult(30, 25);
ASSERT(szOutput == szResult);

/* It works with SIZE, too */

sz1 = CSize(20, 20);
SIZE sz3;
sz3.cx = 10;
sz3.cy = 5;

szOutput = sz1 + sz3;
ASSERT(szOutput == szResult);   
You can also try this code with Online C++ Compiler
Run Code

CSize::operator -

The following first three operators subtract this CSize value to the value of the parameter.

CSize operator-(SIZE size) const throw();
CRect operator-(const RECT* lpRect) const throw();
CPoint operator-(POINT point) const throw();
CSize operator-() const throw();
/*
*  The fourth operator -> the unary minus, 
*  changes the sign of the CSize value.
*/

Example

CSize sz1(20, 20);
CSize sz2(10,  5);
CSize szOut;

szOut = sz1 - sz2;

CSize szResult(10, 15);
ASSERT(szOut == szResult);

/* It works with SIZE, too */

sz1 = CSize(20, 20);
SIZE sz3;
sz3.cx = 10;
sz3.cy = 5;

szOut = sz1 - sz3;
ASSERT(szOut == szResult);
You can also try this code with Online C++ Compiler
Run Code

Frequently Asked Questions

What CSize Class does?

You can send a CSize as a parameter when a SIZE is required, and the data members of the SIZE structure are also available for use with CSize.

What is the use of the SIZE structure?

The SIZE structure defines the width and height of a rectangle. We use windef.h header file to use it.

What is ATL?

ATL stands for Active Template Library. It is a collection of template-based C++ classes that allow you to create small, quick COM(Component Object Model) objects.

Conclusion

In this article, we learned about UtilityClass-CSize. It is one of the several classes provided by Active Template Library.

If you want to explore more, here are some related articles - 


You may refer to our Guided Path on Code Studios for enhancing your skill set on DSACompetitive ProgrammingSystem Design, etc. Check out essential interview questions, practice our available mock tests, look at the interview bundle for interview preparations, and so much more!

Happy Learning, Ninjas!

Live masterclass