Board index » delphi » Form.Color under 256 color mode.

Form.Color under 256 color mode.

In article <8g8q7o$2...@bornews.borland.com>, jamesc...@sympatico.ca
says...
Quote
> Hi,

> I have a form which I want its background color is $B$D4DE( color of
> quicken), but when I run it under 256 mode, system use dither to deal with
> it.
> I've already override the GetPalette function, what else should I do to get
> the correct result ( as quicken ).

Try simply painting that color in an OnPaint handler.

Be sure to set all labels to Transparent=True.

--
Neil J. Rubenking
Contributing Technical Editor
PC Magazine

 

Re:Form.Color under 256 color mode.


Quote
"jameschou" <jamesc...@sympatico.ca> wrote in message

news:8g8q7o$2bl4@bornews.borland.com...

Quote
> I have a form which I want its background color is $B$D4DE( color of
> quicken), but when I run it under 256 mode, system use dither to deal with
> it.
> I've already override the GetPalette function, what else should I do to get
> the correct result ( as quicken ).

Normally, I'd refer you to a previous Deja post that seems to answer your
question.  Unfortuntely, Deja has messed up their archive (I hope temporarily)
and the desired article is not online.  I kept an offline copy and will just
re-post it here:
========================================================
From: "Roelof Engelbrecht" <roe...@nospam.tca.net>
Subject: Re: Non-dithered orange in 256 color mode?
Date: 03 Sep 1998 00:00:00 GMT
Message-ID: <6snotk$kg62@forums.borland.com>
References: <6sfva4$aja2@forums.borland.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.delphi.graphics

I was able to answer my own question, based on an article in the July 1998
issue of Delphi Informant , in case anyone is interested...

1. Add the following to the form's FormCreate event handler:

    {allocate a logical palette}
    GetMem(LogPalette, SizeOf(TLogPalette));  {local var LogPalette:
PLogPalette}
    try
      LogPalette.palVersion := $300;
      LogPalette.palNumEntries := 1;
      {RGB code for orange}
      LogPalette.palPalEntry[0].peRed := 255;
      LogPalette.palPalEntry[0].peGreen := 191;
      LogPalette.palPalEntry[0].peBlue := 0;
      LogPalette.palPalEntry[0].peFlags := 0;
      Palette := CreatePalette(LogPalette^);   {global var Palette:
HPalette, initialized to 0}
      if Palette = 0 then
        RaiseLastWin32Error;
    finally
      FreeMem(LogPalette);
    end;

2. Add the following to the form's FormDestroy event handler:

  {delete the logical palette}
  DeleteObject(Palette);
  Palette := 0;

3. Override form's GetPalette function as follows:

function TForm1.GetPalette: HPalette;
begin
  Result := Palette;
end;

4. In the form of component's Paint event handler add:

      {select palette}
      OldPalette := SelectPalette(Handle, MainForm.GetPalette, False);
{local var OldPalette: HPalette}

      {choose orange color from palette}
      Canvas.Pen.Color := PaletteIndex(0);

      {do drawing here...}

      {restore previous palette}
      SelectPalette(Handle, OldPalette, True);

Works for me! You need to modify this code to add more than a single color
to the logical palette. The process is described in the referenced article.

Roelof

Quote
Roelof Engelbrecht wrote in message <6sfva4$a...@forums.borland.com>...
>I want to display a non-dithered orange color in 256 color mode in Delphi
4.
>I have tried RGB($FF,$7F,00) but it gives me a 50% red 50% yellow dither. I
>guess I have to mess around with the palette. Can anyone help?

>Thanks,
>Roelof

========================================================

--
efg

Earl F. Glynn     E-mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:Form.Color under 256 color mode.


Hi,

Thanks for reply,

But this still not resolve my problem.

What am I doing is not just CreatePalette,SelectPalette, RealizePalette,
drawing sth. SelectOldPalette,DeleteObject.
I want all the controls or subforms which contains the color use the index
in palette, not in dither mode.

e.g.

In my form, I have 2 panel. I want the color of them should be $00B4D4DE and
$7179BA.
Of course, these two colors are not in standard palette( 20 colors ).  I
have my own palette,
which I get out of Quicken, so I just override the GetPalette funciton to
return this palette.

My best result is:  If you assign the color of a panel as $100000000 +
IndexInPalette, and after that,
call Form.Perform( WM_PALETTECHANGED,0,0);, you got the correct result, but,
the question is:
I must write an extra function to do this color initialization for almost 30
forms, and with each of them,
must assign the color of many controls. ( I have to do it because if in
truecolor mode, I assign them the
RGB value, in 256 mode, I assign them the Index + $10000000 value.)

So, I wonder if there is some better way to do this? Maybe do some hook at
Microsfot Color Manager?

Thansk.

James.

Earl F. Glynn <EarlGl...@att.net> wrote in message
news:8gbepg$t0b13@bornews.borland.com...

Quote
> "jameschou" <jamesc...@sympatico.ca> wrote in message
> news:8g8q7o$2bl4@bornews.borland.com...

> > I have a form which I want its background color is $B$D4DE( color of
> > quicken), but when I run it under 256 mode, system use dither to deal
with
> > it.
> > I've already override the GetPalette function, what else should I do to
get
> > the correct result ( as quicken ).

> Normally, I'd refer you to a previous Deja post that seems to answer your
> question.  Unfortuntely, Deja has messed up their archive (I hope
temporarily)
> and the desired article is not online.  I kept an offline copy and will
just
> re-post it here:
> ========================================================
> From: "Roelof Engelbrecht" <roe...@nospam.tca.net>
> Subject: Re: Non-dithered orange in 256 color mode?
> Date: 03 Sep 1998 00:00:00 GMT
> Message-ID: <6snotk$k...@forums.borland.com>
> References: <6sfva4$a...@forums.borland.com>
> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0
> Organization: Another Netscape Collabra Server User
> Newsgroups: borland.public.delphi.graphics

> I was able to answer my own question, based on an article in the July 1998
> issue of Delphi Informant , in case anyone is interested...

> 1. Add the following to the form's FormCreate event handler:

>     {allocate a logical palette}
>     GetMem(LogPalette, SizeOf(TLogPalette));  {local var LogPalette:
> PLogPalette}
>     try
>       LogPalette.palVersion := $300;
>       LogPalette.palNumEntries := 1;
>       {RGB code for orange}
>       LogPalette.palPalEntry[0].peRed := 255;
>       LogPalette.palPalEntry[0].peGreen := 191;
>       LogPalette.palPalEntry[0].peBlue := 0;
>       LogPalette.palPalEntry[0].peFlags := 0;
>       Palette := CreatePalette(LogPalette^);   {global var Palette:
> HPalette, initialized to 0}
>       if Palette = 0 then
>         RaiseLastWin32Error;
>     finally
>       FreeMem(LogPalette);
>     end;

> 2. Add the following to the form's FormDestroy event handler:

>   {delete the logical palette}
>   DeleteObject(Palette);
>   Palette := 0;

> 3. Override form's GetPalette function as follows:

> function TForm1.GetPalette: HPalette;
> begin
>   Result := Palette;
> end;

> 4. In the form of component's Paint event handler add:

>       {select palette}
>       OldPalette := SelectPalette(Handle, MainForm.GetPalette, False);
> {local var OldPalette: HPalette}

>       {choose orange color from palette}
>       Canvas.Pen.Color := PaletteIndex(0);

>       {do drawing here...}

>       {restore previous palette}
>       SelectPalette(Handle, OldPalette, True);

> Works for me! You need to modify this code to add more than a single color
> to the logical palette. The process is described in the referenced
article.

> Roelof

> Roelof Engelbrecht wrote in message <6sfva4$a...@forums.borland.com>...
> >I want to display a non-dithered orange color in 256 color mode in Delphi
> 4.
> >I have tried RGB($FF,$7F,00) but it gives me a 50% red 50% yellow dither.
I
> >guess I have to mess around with the palette. Can anyone help?

> >Thanks,
> >Roelof

> ========================================================

> --
> efg

> Earl F. Glynn     E-mail:  EarlGl...@att.net
> Overland Park, KS  USA

> efg's Computer Lab:  http://www.efg2.com/Lab

Other Threads