Book Image

Microsoft Visual C++ Windows Applications by Example

By : Stefan Bjornander, Stefan Björnander
Book Image

Microsoft Visual C++ Windows Applications by Example

By: Stefan Bjornander, Stefan Björnander

Overview of this book

Table of Contents (15 chapters)
Microsoft Visual C++ Windows Applications by Example
Credits
About the Author
About the Reviewer
Preface
Index

The Color Class


In the Ring and Tetris applications, we used the type COLORREF, which manages a color according to the RGB standard. However, it would be nice to have a class encapsulating it, so let us write the Color class. COLORREF is a 32 bit value, even thought it only uses the lower 24 bits. A color consists of the three basic colors red (bits 0 – 7), green (bits 8 – 15), and blue (bits 16 – 23). The macro RGB puts together a COLORREF value given its red, green, and blue portions. There are also macros GetRValue, GetGValue, and GetBValue that extract the red, green, and blue parts of the color, respectively.

In the Ring and Tetris applications of this book, the type COLORREF is used. In the Draw, Calc, and Word applications, the class Color is used.

As object of this class will be serialized. The class must include a default constructor. The constructor sets the color to zero, which represents black. Moreover, there is a copy constructor, a constructor taking a COLORREF value, and...