Solved

"ZIF Help converting MS C sample code"

Posted on 1998-03-06
6
252 Views
Last Modified: 2010-04-06
How do I use  CreateIdentityPalette(I HAVE 281 POINTS LEFT IN MY ACCT,CreateDIBSectionFromFile(FName: PChar): HBITMAP, PrepareDIBSectionForIdentityP) THEY ARE YOURS, thanks alot!)
/STEVE

RONIT, I'm sorry this question was placed in error and as stated is misleading. Your answer is excellent however.
The question was answered 3/6/97 by zif & Igor and I was trying to pass points to zif.
Please see previous question "Help converting MS C sample code" entered 3/5/98.

Zif please talk to Igor, he'll explain.
/thanks all
0
Comment
Question by:sz3905
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:ronit051397
Comment Utility
This is something I have got from Delphi-Talk: delphi-talk@bridge.net

47. Creating and selecting palettes
Q:
How do you create and use a Palette in Delphi. According to the help fn I
think you should use the CreatePalette and SetPaletteEntries and RealizePalette
but how?

A:
Below are functions that help to create a palette (an identity
palette, BTW) from an array of RGBQuads (such as you would find in
the palette section of a .BMP file). I stole this from the WinG
documentation, and converted it to Delphi. First call
ClearSystemPalette, then you can get an identity palette by calling
CreateIdentityPalette.

 If you plan to try palette animation, work in a 256-color mode, and
change all the PC_NOCOLLAPSE entries below to PC_RESERVED.

Besides creating the palette, the other pieces to the puzzle are

1. Override the form's GetPalette method, so that it returns the
new palette.

2. Select and realize the new palette just before you paint.

  OldPal := SelectPalette(Canvas.Handle, NewPalette, False);
  RealizePalette(Canvas.Handle);  
  { Do your painting here }
  SelectPalette(Canvas.Handle, OldPal, False);

3. Remember to release the palette when you are done using
DeleteObject

4. If you are used to using the RGB function to get color values, use
the PaletteRGB function in its place.

function CreateIdentityPalette(const aRGB; nColors : Integer) : HPALETTE;
type
  QA = Array[0..255] of TRGBQUAD;
var
  Palette : PLOGPALETTE;
  PalSize : Word;
  ScreenDC : HDC;
  I : Integer;
  nStaticColors : Integer;
  nUsableColors : Integer;
begin
  PalSize := SizeOf(TLOGPALETTE) + SizeOf(TPALETTEENTRY) * 256;
  GetMem(Palette, PalSize);
  try
    with Palette^ do
      begin
        palVersion := $0300;
        palNumEntries := 256;
        ScreenDC := GetDC(0);
        try
          { For SYSPAL_NOSTATIC, just copy the color table into a PALETTEENTRY
            array and replace the first and last entries with black and white }
          if (GetSystemPaletteUse(ScreenDC) = SYSPAL_NOSTATIC)
            then
              begin
              { Fill in the palette with the given values, marking each
                  with PalFlag }
                {$R-}
                for i := 0 to (nColors-1) do
                with palPalEntry[i], QA(aRGB)[I] do
                  begin
                    peRed := rgbRed;
                    peGreen := rgbGreen;
                    peBlue := rgbBlue;
                    peFlags := PC_NOCOLLAPSE;
                  end;

                { Mark any unused entries with PalFlag }
                for i := nColors to 255 do
                  palPalEntry[i].peFlags := PC_NOCOLLAPSE;

                { Make sure the last entry is white --
                  This may replace an entry in the array!}
                I := 255;
                with palPalEntry[i] do
                  begin
                    peRed := 255;
                    peGreen := 255;
                    peBlue := 255;
                    peFlags := 0;
                  end;

                { And the first is black --
                  This may replace an entry in the array!}
                with palPalEntry[0] do
                  begin
                    peRed := 0;
                    peGreen := 0;
                    peBlue := 0;
                    peFlags := 0;
                  end;
                {$R+}
              end
            else
              begin
              { For SYSPAL_STATIC, get the twenty static colors into the
                  array, then fill in the empty spaces with the given color
                  table }

                { Get the static colors from the system palette }
                nStaticColors := GetDeviceCaps(ScreenDC, NUMRESERVED);
                GetSystemPaletteEntries(ScreenDC, 0, 256, palPalEntry);

                {$R-}
                { Set the peFlags of the lower static colors to zero }
                nStaticColors := nStaticColors shr 1;
                for i:= 0 to (nStaticColors-1) do
                  palPalEntry[i].peFlags := 0;

                { Fill in the entries from the given color table}
                nUsableColors := nColors - nStaticColors;
                for I := nStaticColors to (nUsableColors-1) do
                  with palPalEntry[i], QA(aRGB)[i] do
                    begin
                      peRed := rgbRed;
                      peGreen := rgbGreen;
                      peBlue := rgbBlue;
                      peFlags := PC_NOCOLLAPSE;
                    end;

                { Mark any empty entries as PC_NOCOLLAPSE }
                for i := nUsableColors to (255-nStaticColors) do
                  palPalEntry[i].peFlags := PC_NOCOLLAPSE;

                { Set the peFlags of the upper static colors to zero }
                for i := (256 - nStaticColors) to 255 do
                  palPalEntry[i].peFlags := 0;
              end;
        finally
          ReleaseDC(0, ScreenDC);
        end;
      end;
    { Return the palette }
    Result := CreatePalette(Palette^);
  finally
    FreeMem(Palette, PalSize);
  end;
end;


procedure ClearSystemPalette;
var
  Palette : PLOGPALETTE;
  PalSize : Word;
  ScreenDC : HDC;
  I : Word;
const
  ScreenPal : HPALETTE = 0;
begin
  PalSize := SizeOf(TLOGPALETTE) + SizeOf(TPALETTEENTRY) * 255; {256th = [0] }
  GetMem(Palette, PalSize);
  try
    FillChar(Palette^, PalSize, 0);
    Palette^.palVersion := $0300;
    Palette^.palNumEntries := 256;
{$R-}
    For I := 0 to 255 do
      With Palette^.palPalEntry[I] do
        peFlags := PC_NOCOLLAPSE;
{$R+}
    { Create, select, realize, deselect, and delete the palette }
    ScreenDC := GetDC(0);
    try
      ScreenPal := CreatePalette(Palette^);
      if ScreenPal <> 0
        then
          begin
            ScreenPal := SelectPalette(ScreenDC,ScreenPal,FALSE);
            RealizePalette(ScreenDC);
            ScreenPal := SelectPalette(ScreenDC,ScreenPal,FALSE);
            DeleteObject(ScreenPal);
          end;
    finally
      ReleaseDC(0, ScreenDC);
    end;
  finally
    FreeMem(Palette, PalSize);
  end;
end;

[Eric Nielsen, htrsoft@midwest.net]

0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
?? sz3905, what do you exactly mean ??

In what can I be of assistance?

Regards, Zif.
0
 

Author Comment

by:sz3905
Comment Utility
Edited text of question
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:sz3905
Comment Utility
Edited text of question
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 280 total points
Comment Utility
Hi sz3905,

I understand now, that it is for the help I gave at the question concerning 'fading in C source'. I find it a lot of points for that little help I gave you. I don't mind if you want to use them for other questions. So it's up to you. You can use them for asking other question or you can give them to me now (like you want at the moment). If you give them to me, I thank you a lot... But as I said, maybe you can use them for other questions...

Glad to hear the problem is solved, because I wasn't on the net anymore when you graded the answer.

Regards, Zif.

Always here to help you, if I can.

0
 

Author Comment

by:sz3905
Comment Utility
Thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now