Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

color question 1

Status
Not open for further replies.

misterhux

Programmer
Aug 27, 2003
36
0
0
US
does anyone know what the RGB values for the dis-enabled controls are? (That nice lovely beige)

thanks
 
I think you're probably talking about a system palette color. The system palette is a set of colors that Windows uses for things like the active window background, "3D" controls, foreground text, etc. They are set on the Appearance page of the Control Panel's Display Properties applet.

BTW, what's beige to you could be a completely different color to somebody else. Choosing a different Appearance scheme will totally change the actual color seen.

There are two ways to get a system palette color displayed. One is to use the Display Properties dialog. On the Appearance page, click on the part of the picture that corresponds to the window component whose color you want. Then click the Color button, and click the Other button on the dropdown palette. This will open the Windows standard Color dialog, and you can read the RGB values from there.

However, if you use actual RGB values, then your color won't stay coordinated with Windows when the user changes the Appearance scheme. To stay coordinated, you need to use the system color constants, which are documented in the help file under, naturally, "System Color Constants". These constants are single numbers (not RGB triples) that select one of the types of objects on the Appearance page. When you assign one of these constants to a color property, such as BackgroundColor, you automatically get the color of the corresponding object on the Appearance page, and if the user changes the Appearance scheme, your form or control changes instantly without any VBA code.

Some of the names used in the System Color Constants help topic don't quite match those used on the Appearance page, but you can figure it out with a little experimentation.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
To answer your question about the specific RGB values of a disabled control, you first will need to know if the specific color is a specific RGB value, a System Color Constant, or very rarely anymore, a index into a color palette.

The color is represented by a long value that is 4 bytes longs. The first byte indicates how the remaining bytes are to be interpreted. For the most part, it is safe to assume that if the color value is negative (the MSB of the first byte is set), then you dealing with a system color constant, which when rendered, will vary depending on the color scheme chosen using the Display Properties. However, if the number is positive, then the color is a specific RGB composite and will render the same regardless of the chosen appearance scheme. Exceptions include an index value into a color palette, or a best fit match from a specific color to a palette color, or transparency.

Putting aside those exceptions, you can for the most part assume that is the color number you see is negative, then the remaining three bytes indicate a system color constant which when rendered, will vary depending on the color scheme chosen using the Display Properties. To get the specific RGB values for that color in the current appearance selection, you will first need to call the GetSysColor API which will return a true RGB color corresponding to the system color constant for those appearance settings.

On the other hand, if the number is positive, then the value already represents a true RGB color that will always be the same regardless of the current display settings. Once you have the true RGB color, either directly or via the API call, you can extract the three components using the following code:

CurrColor = TheControl.BackColor
RedShade = (CurrColor And 255)
GreenShade = (CurrColor And 65280) / 256


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top