Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1
Visual C++ and MFC Fundamentals Chapter 8 GDI Orientation and Transformations

As the pixels close to each other have different colors, the effect is a wonderful distortion
that creates an aesthetic picture. It is by changing the colors of pixels that you produce
the effect of color variances seen on pictures and other graphics.

7.1.2 The Color as a Data Type...................................................................


Microsoft Windows considers that a color is a 32-bit numeric value. Therefore, a color is
actually a combination of 32 bits:

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0


The bits of the most significant byte (the left byte) are reserved for the operating system's
internal use and must be set to 0. Based on this, each color is characterized by its
combination of a red, a green, and a blue values.

When all three numbers have their lowest value, which is 0, the color is called black.
When the numbers are at their highest value, which is 255, the color is called white. Not
all color combinations have a name. In fact, in MS Windows programming, the names
are very limited. For this reason, color are rarely called by a name and usually, a name
would depend on who is using it. Nevertheless, there are popular names that most people
recognize. Examples are Black, White, Red, Green, Blue, Yellow. Except for black and
white, each color can assume different variations. For example, when all three numbers
have the same value but neither 0 nor 255, the color is called Gray by there are more than
250 possible combinations. Sometimes the combination is called Silver (each value is
192) or Gray (values=128).

The 32-bit numeric value used to characterize a color is defined by the COLORREF data
type in Microsoft Windows programming. It can be used to declare a color value. Here is
an example:

void CExoView::OnDraw(CDC* pDC)
{
Free download pdf