【问题标题】:Converting Inno Setup WizardForm.Color to RGB将 Inno Setup WizardForm.Color 转换为 RGB
【发布时间】:2015-06-22 17:54:33
【问题描述】:

如果我试试这个:

[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】:

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

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

    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;
    

    ColorToRGB code 复制自 Delphi VCL(Vcl.Graphics 单元)。


    以上代码返回 Win32 API 颜色,$BBGGRR 是什么。如果你需要$RRGGBB,你需要交换位:

    Result :=
      ((Result and $FF) shl 16) +
      (Result and $FF00) +
      ((Result and $FF0000) shr 16);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 2019-03-28
      • 2012-04-11
      • 2017-03-11
      • 2016-06-27
      • 1970-01-01
      相关资源
      最近更新 更多