Getting the palette color of a system color 
Author Message
 Getting the palette color of a system color

Hi, guys, I want to get a system color using the GetSysColor API call,
which returns a long.

The problem is this: I don't want to set some other control.BackColor to
the long that I get from GetSysColor, I want to display it in hex, like
this: &H00FFFFFF&, just like VB does when displaying the .BackColor on a VB
control property sheet.

How on Earth do you convert a long to a string representation in hex?
Please don't say to convert the long to hex mathematically, because I have
tried that, and it does not appear to work.  The color that you get back
from Windows does not represent the mathematical value of a long, but
rather the bit pattern in the three lowest bytes - FF FF FF, or 256
possible values each for red, green, and blue.

What I am thinking about doing is either using the CopyMem API call to
overlay a string with the long and then parsing out the string byte by
byte.  I also am considering writing a C DLL that I can call to do this,
but I don't want to do this unless there is no other way, because of code
maintenance issues.

Does anyone have an opinion about the best way to do this?



Sun, 30 Apr 2000 03:00:00 GMT  
 Getting the palette color of a system color

Quote:
> How on Earth do you convert a long to a string representation in hex?
> Please don't say to convert the long to hex mathematically, because I
have
> tried that, and it does not appear to work.  The color that you get back
> from Windows does not represent the mathematical value of a long, but
> rather the bit pattern in the three lowest bytes - FF FF FF, or 256
> possible values each for red, green, and blue.

I tried this on my system, and just setting the .BackColor property to the
long returned from GetSysColor worked ok:
Let's say that the sys color is 8421376 (The standard green background rgb
value)
label1.BackColor = 8421376

but if you do want to use the hex value then you can do this:
label1.BackColor = "&h" & hex(8421376)

HTH
--
Michael Cody
remove the "spam" from the address

Quote:
> How on Earth do you convert a long to a string representation in hex?
> Please don't say to convert the long to hex mathematically, because I
have
> tried that, and it does not appear to work.  The color that you get back
> from Windows does not represent the mathematical value of a long, but
> rather the bit pattern in the three lowest bytes - FF FF FF, or 256
> possible values each for red, green, and blue.



Sun, 30 Apr 2000 03:00:00 GMT  
 Getting the palette color of a system color


Quote:
>Hi, guys, I want to get a system color using the GetSysColor API call,
>which returns a long.

>The problem is this: I don't want to set some other control.BackColor to
>the long that I get from GetSysColor, I want to display it in hex, like
>this: &H00FFFFFF&, just like VB does when displaying the .BackColor on a VB
>control property sheet.

>How on Earth do you convert a long to a string representation in hex?
>Please don't say to convert the long to hex mathematically, because I have
>tried that, and it does not appear to work.  The color that you get back
>from Windows does not represent the mathematical value of a long, but
>rather the bit pattern in the three lowest bytes - FF FF FF, or 256
>possible values each for red, green, and blue.

>What I am thinking about doing is either using the CopyMem API call to
>overlay a string with the long and then parsing out the string byte by
>byte.  I also am considering writing a C DLL that I can call to do this,
>but I don't want to do this unless there is no other way, because of code
>maintenance issues.

>Does anyone have an opinion about the best way to do this?

I use wsprintf. I know you can call API functions from VB, but I don't know
where you'd find this - possibly KERNEL or USER.

Pete Barrett



Mon, 01 May 2000 03:00:00 GMT  
 Getting the palette color of a system color

Absolutely!  This works perfectly, thanks.

- - - - - - - - - - - - - - - - - - - - - - - - - - -
- George Copeland
- Vectrix Corporation, Publishers of EdgeworX
- http://www.vectrix.com/edgehome.htm


Quote:
> I tried this on my system, and just setting the .BackColor property to
the
> long returned from GetSysColor worked ok:
> Let's say that the sys color is 8421376 (The standard green background
rgb
> value)
> label1.BackColor = 8421376

> but if you do want to use the hex value then you can do this:
> label1.BackColor = "&h" & hex(8421376)



Wed, 03 May 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Getting the palette color of a system color

2. Using a Custom color from the color palette.

3. Using 256 color Palettes in High/True Color

4. choose a color in a 256 color palette ?

5. color palette-define color

6. Change Screen Color Palette from 256 to hi-color in VB

7. Bitmap Color Palette editing-VB4 16 bit 256 color

8. Problems with color palette colors being dithered

9. Is ImageList color palette just 16 colors?

10. Coloring a control from a 256-Color palette

11. Coloring a control from a 256-Color palette

12. color palette not accessible in 256+ color settings

 

 
Powered by phpBB® Forum Software