将Inno Setup WizardForm.Color转换为RGB

Converting Inno Setup WizardForm.Color to RGB

如果我尝试这样做:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[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;

我得到:红色:15绿色:0蓝色:0
但结果应为:240 240 240(灰色)

怎么了?

我需要获取正确的TColor并将其转换为RGB颜色代码。


当第一个字节为$FF时,最后一个字节为系统调色板中的索引。

您可以使用GetSysColor函数获得系统颜色的RGB。

1
2
3
4
5
6
7
8
9
function GetSysColor(nIndex: Integer): DWORD;
  external '[email protected] stdcall';

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

ColorToRGB代码是从Delphi VCL(Vcl.Graphics单元)复制而来的。