Link to home
Start Free TrialLog in
Avatar of biroadam
biroadam

asked on

clButtonX colors in CoolBar.Bitmap

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?
Avatar of viktornet
viktornet
Flag of United States of America image

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

Regards,
Viktor Ivanov
Avatar of biroadam
biroadam

ASKER

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?
  CoolBar1.Bitmap:=ListView1.???
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....

const
   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........
begin
   Form1.Color := clButtonFace;//You can also assign the other colors...
end;

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

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

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

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

Regards,
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:
const
   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).

Regards,
Adam Biro
ASKER CERTIFIED SOLUTION
Avatar of erajoj
erajoj
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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

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

procedure TForm1.WMSysColorChange(var Message: TWMSysColorChange);
begin
  inherited;
  MapCoolBarBitmap;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // save original CoolBar bitmap
  FCoolBarBitmap := TBitmap.Create;
  FCoolBarBitmap.Assign(Coolbar1.Bitmap);
  MapCoolBarBitmap;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FCoolBarBitmap.Free;
end;

 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).