The information in this article applies to:
SUMMARYThis article lists a function (Dec2RGB) that you can use to determine which color values have been chosen in an application that allows custom color settings. MORE INFORMATION
When colors are assigned through the Property Sheet, they are displayed in
the sheet as individual red, green, and blue (RGB) values -- separated by
commas. However, the actual value assigned to the object internally is the
decimal equivalent of a hexadecimal number that has the individual red,
green, and blue values encoded positionally.
Each color can be set within a range of 0 to 255, so it is difficult to
determine from a single decimal value the color the user chose. With the
exception of black (0), it is hard to distinguish all the potential colors
ranging up to white (16777215). The individual colors can be parsed to
compare with other color settings to avoid potential problems due to
extremes in contrast, and reset other colors in the interface to
accommodate the custom settings.
The function in this article converts the number to hexadecimal, extracts the individual RGB values, then converts the results for each value to decimal and returns the result as a string in the expected RGB format. The value that FoxPro assigns to an object's color property consists of a double word in hexadecimal notation. The first byte of the first word is ignored. The remaining three bytes indicate the individual red, green, and blue values in the following format:
Note that the blue and red values are reversed when encoded, and must be
manipulated to be presented in the expected RGB format.
The first section of the function converts the decimal value to hexadecimal by factoring the next highest exponent of 2 contained within the decimal value, and so on until the remaining factor is 1. Once converted, the resulting string is parsed and the first and third bytes are swapped so that they are in Red-Green-Blue order. The final section reverts the hexadecimal value of each pair back to a decimal value between 0 and 255, representing the intensity of the color that it indicates. The colors values are then concatenated and returned to the calling program in the RGB format. The code may be used as a method within a class or form, or as a function within a .prg or procedure file. Dec2RGB Function Code
Additional query words: HLS HBS vfp hex VFoxWin
Keywords : kbcode FxprgGeneral |
Last Reviewed: December 10, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |