Convert Inno Setup WizardForm.Color to RGB

If I try this:

[Setup]
AppName=MyApp
AppVerName=MyApp
DefaultDirName={pf}\MyApp
DefaultGroupName=MyApp
OutputDir=.

[Code]
function ColorToRGBstring(Color: TColor): string;
var
  R,G,B : Integer; 
begin 
  R := Color and $ff; 
  G := (Color and $ff00) shr 8; 
  B := (Color and $ff0000) shr 16; 
  result := 'red:' + inttostr(r) + ' green:' + inttostr(g) + ' blue:' + inttostr(b); 
end;

procedure InitializeWizard();
begin
  MsgBox(ColorToRGBstring(WizardForm.Color),mbConfirmation, MB_OK);
end;

      

I get: red: 15 green: 0 blue: 0
But the result should be: 240 240 240 (gray)

What's wrong?

I need to get the correct one TColor

and convert it to RGB color code.

+4


source to share


1 answer


When the first byte is equal $FF

, the last byte is the index in the system color palette.

You can get RGB system color using the function . GetSysColor



function GetSysColor(nIndex: Integer): DWORD;
  external 'GetSysColor@User32.dll stdcall';

function ColorToRGB(Color: TColor): Cardinal;
begin
  if Color < 0 then
    Result := GetSysColor(Color and $000000FF) else
    Result := Color;
end;

      

Code copied from Delphi VCL (Vcl.Graphics module). ColorToRGB

+4


source







All Articles