将Inno Setup WizardForm.Color转换为RGB

问题描述 投票:4回答:1

如果我试试这个:

[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颜色代码。

inno-setup rgb tcolor
1个回答
4
投票

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

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

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 code是从Delphi VCL(Vcl.Graphics单元)复制而来的。

© www.soinside.com 2019 - 2024. All rights reserved.