We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


clButtonX colors in CoolBar.Bitmap

biroadam asked
Medium Priority
Last Modified: 2008-02-01
How can I put a clButtonFace, clButtonHighlight and clButtonShadow based bitmap in the Bitmap property of a CoolBar (clButtonFace<>clSilver!!!) -- like in the Microsoft Internet Explorer 3.x?
Watch Question

Have an ImageList component that contains the three images, and when needed use the appropriate one..

Viktor Ivanov


1. There is ONE BITMAP which contains clButtonFace, clButtonHighlight and clButtonShadow colors (beside other colors).
2. The ListView component doesn’t have a Bitmap property, so I can’t put a bitmap from an ImageList into a CoolBar.
I'm not sure what you're talking about! Please provide an example source...

>2. The ListView component doesn’t have a Bitmap property, so I can’t put a
>     bitmap from an ImageList into a CoolBar.

What do you mean by this???

//Viktor Ivanov


 I want my CoolBar’s bitmap just like the Internet Explorer’s, so the bitmap must contain the clButtonHighlight color. Becouse the clButtonHighlight isn’t a certain color, I have to make a bitmap using clSilver, for example, instead of clButtonHighlight, and I have to substitute it.
  It’s true that the ListView component has a few properties for color control, but
  1. I’m not sure that it’s enough to resolve my problem
  2. I don’t know how can I get a bitmap from a ListView component?
Just one question....

Why do you need a bitmap for that thing to happen....Can't you use the ColorDialog component just to see what's the hex values for the colors you need, and then assign those values to the colors....

For example it would be something like this....

   clButtonFace = $000040
   clButtonHighlight =  $00F040
   clButtonShadow =   $0F0040
{I'm not sure if there are colors like this but just to show you what it is suppose to look like}
procedure Whatever........
   Form1.Color := clButtonFace;//You can also assign the other colors...

If that's not what you want or don't understand how to do it just tell me what each of the colors suppose to look like....Ex. clButtonFace = Similar to clSilver...or something like that

Viktor Ivanov
Another example, but this time a real color value ....

  OneOfManyOranges = $000080FF;//This is orange color
procedure whatever.....
  Form1.Color := OneOfManyOranges;//Now the color of the form will become orange

Is that what you were looking for...???

Viktor Ivanov


Dear Viktor Ivanov,

Thank you for your time, bu I still got no answer for my problem.
I will try to explain it again.
There is no reason to do something like this:
   clButtonFace = $000040
   clButtonHighlight =  $00F040
   clButtonShadow =   $0F0040,
becouse clButtonFace is the current color of the buttons’ face, and it’s provided by Windows (and can be changed in Display Properties / Appearance box; for example, choosing the "Desert" scheme). So my program’s purpose is to display a bitmap (as the background bitmap of a CoolBar component) using the current button colors (it’s very ugly a gray-colored bitmap on sand-colored window, beside of sand-colored buttons).
  If I do not hide the Windows-provided clButtonFace system variable (as you proposed), my program will know the current button color on any computer, and I think it’s possible to substitute some colors in a bitmap with these system colors. I wish to know how.
  A concrete example: make a bitmap, for example some ellipses (like in the MS Internet Explorer 3.x), and display it as a TCoolBar background bitmap. If you have a standard color scheme, the bitmap’s (CoolBar’s) background will be clGray and the ellipses will have clSilver color. If you change your color scheme -- for example choosing Desert color scheme --, the same bitmap in the same program must be automatically sand-colored, not gray-colored. (If you have an Internet Explorer 3.x, you can see how it works).

Adam Biro
Unlock this solution and get a sample of our free trial.
(No credit card required)

There are functions CreateMappedBmp and CreateGrayMappedBmp
in the graphics.pas

function CreateMappedBmp(Handle: HBITMAP; const OldColors,
NewColors: array of TColor): HBITMAP;
{ This function will replace OldColors in Handle's colortable
with NewColors and return a new DDB which uses that color table.
For bitmap's with more than 256 colors (8bpp)
this function returns the original bitmap. }

function CreateGrayMappedBmp(Handle: HBITMAP): HBITMAP;
{ This function replaces the standard gray colors
in a bitmap with the system grays }

So, try it

  TForm1 = class(TForm)
    CoolBar1: TCoolBar;
    ToolBar1: TToolBar;
    ToolBar2: TToolBar;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    FCoolBarBitmap: TBitmap;
    procedure WMSysColorChange(var Message: TWMSysColorChange); message WM_SYSCOLORCHANGE;
    procedure MapCoolBarBitmap;

procedure TForm1.MapCoolBarBitmap;
  // replace the standard gray colors in a bitmap
  // with the system grays
  CoolBar1.Bitmap.Handle := CreateGrayMappedBmp(FCoolBarBitmap.Handle);

procedure TForm1.WMSysColorChange(var Message: TWMSysColorChange);

procedure TForm1.FormCreate(Sender: TObject);
  // save original CoolBar bitmap
  FCoolBarBitmap := TBitmap.Create;

procedure TForm1.FormDestroy(Sender: TObject);


 To erajoy: Thank you, John, it is a good answer.

  To vladika: I liked your comment very much, and I choosed your version. I have only one further question:
  Creating a new bitmap with the CreateGrayMappedBmp function, isn’t neccessary to destroy it? You destroyed only that bitmap which was created by the TBitmap.Create method.

>Creating a new bitmap with the CreateGrayMappedBmp function, isn’t neccessary to destroy it?

I think you are not neccessary to destroy it. Why?
Because you assign new bitmap's handle (created by
CreateGrayMappedBmp) to CoolBar1.Bitmap.Handle.
And Delphi automatically destroys new bitmap for you.
(when CoolBar1.Bitmap is destroyed).

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.