Microsoft Windows is a graphical operating system. It uses colors to present the windows, controls, and other objects on the monitor. The operating system uses a series of colors defined in the Window Color and Appearance dialog box of the Control Panel:
Microsoft Windows considers a color as a combination of three numeric values are used to create or specify a color. Each one of these values is 8 bits. The first number is called red. The second is called green. The third is called blue:
Converted to decimal, each one of these numbers would produce: 27 + 26 + 25 + 24
+ 23 + 22 + 21 + 20 Therefore, each number can have a value that ranges from 0 to 255 in the decimal system. These three numbers are combined to produce a single value as follows:
Converted to decimal, this number has a value of 255 * 255 * 255 = 16581375. This means that we can have approximately 16 million colors available.
Microsoft Windows characterizes a color as a 32-bit long integer value. Therefore, a color is actually a combination of 32 bits. 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. The 32-bit numeric value used by the Win32 library to characterize a color is defined as the COLORREF data type: typedef DWORD COLORREF; typedef DWORD* LPCOLORREF; You can use the COLORREF type to declare a color variable. Here is an example: COLORREF ClrMine; As you can see, the COLORREF is just a32-bit unsigned integer. When or after declaring such a variable, you can initialize it with a 32-bit decimal value. Here is an example: COLORREF ClrMine = 1637623;
Although the above number (1637623) is a legitimate color value, it is difficult to identify and predict as its red, green, and blue values are not known. To create a color value, the Win32 API provides the RGB macro. Its syntax is: COLORREF RGB(BYTE byRed, BYTE byGreen, BYTE byBlue); The RGB macro behaves like a function and requires three numeric values separated by a comma. Each value must range between 0 and 255 both included. Using RGB, the above initialization can be done as follows: COLORREF ClrMine = RGB(247, 252, 24);
Whether a color was initialized with a 32-bit long integer, the RGB macro, or a valid color name, if you want to retrieve the red, green, and blue values of a color, you can use the GetRValue(), the GetGValue(), and/or the GetBValue() macros to extract the value of each. The syntaxes of these macros are: BYTE GetRValue(DWORD rgb); BYTE GetGValue(DWORD rgb); BYTE GetBValue(DWORD rgb); Each macro takes a 32-bit value as argument, rgb. The GetRValue() macro returns the red value of the rgb parameter. The GetGValue() macro returns the green value of the rgb number. The GetBValue() macro returns the blue value of rgb.
When all three red, green, and blue numbers of a color have their lowest value, which is 0, the color is referred to as black. When the numbers are at their highest value, which is 255, the color qualifies as white. Just like you, because users are able and free to change the colors of their computer, it is almost impossible to predict the appearance of these colors on someone else’s machine. Fortunately, if you want to use one of the systeme-defined colors, you can ask your application to check its value on the user’s computer. To do this, you can call the GetSysColor() function. Its syntax is: DWORD GetSysColor(int nIndex); This function receives a constant value that is defined in the operating system representing one of the appearance’s colors and returns the 32-bit value of that color. The colors defined in Control Panel can be passed as the nIndex argument of the GetSysColor() function are:
Device independence is the ability for an application to draw its intended figures, text, shapes, and display colors regardless of the device on which the drawing is performed. One way to take care of this is to manage colors at the operating system level so that Microsoft Windows can select the right color to render an object or portion of it. In some cases, a device, such as a monitor or a printer, may need to take care of the coloring details of the job(s) it is asked to perform. A color palette is a list of colors that a device can display. For example, one device may be able to handle only two colors. Such is the case for a black and white printer. Another device could be able to use more colors than that. To control this situation, Microsoft Windows keeps track of the color palette of each device installed on the computer. There are two types of color palettes. The default color palette is a list of colors that the operating system would use on a device unless notified otherwise. There are typically 20 reserved colors as default. A logical palette is a palette that an application creates for a specific device context. |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|