Converting Inno Setup WizardForm.Color to RGB

╄→尐↘猪︶ㄣ 提交于 2019-12-01 04:11:07

问题


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 (grey)

What is wrong?

I need to get the proper TColor and convert it to RGB color code.


回答1:


When the first byte is $FF, the last byte is an index in a system color palette.

You can get RGB of the system color using GetSysColor function.

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;

The ColorToRGB code is copied from Delphi VCL (Vcl.Graphics unit).



来源:https://stackoverflow.com/questions/30986658/converting-inno-setup-wizardform-color-to-rgb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!