如何更改 Inno Setup 中进度条的颜色?

问题描述 投票:0回答:2

我使用

TNewProgressBar
创建进度条。
进度条的默认颜色是绿色。
我想将颜色更改为蓝色。

inno-setup pascalscript
2个回答
7
投票

你不能。


进度条的样式由当前的 Windows 主题决定。在默认的 Windows 主题中,进度条为绿色(或黄色或红色,如果进度条处于暂停或错误状态,请参阅

TNewProgressBar.State
)。

您必须完全重新实现进度条的绘制或禁用整个安装程序的视觉主题。
请参阅如何在 C# .NET 3.5 中更改进度条的颜色?

使用 Inno Setup API,重新实现绘图将非常困难(如果有可能的话)。而且您可能不想禁用视觉主题。


如果你确实需要蓝色,你可以考虑使用

TBitmapImage.Bitmap.Canvas
自己实现进度条(使用类似
.Rectangle
的方法)。

一个简单的例子:

var
  ProgressImage: TBitmapImage;

procedure InitializeWizard();
begin
  ProgressImage := TBitmapImage.Create(WizardForm);
  ProgressImage.Parent := WizardForm;
  ProgressImage.Anchors := [akLeft, akBottom];
  ProgressImage.Left := ScaleX(10);
  ProgressImage.Top := WizardForm.ClientHeight - ScaleY(34);
  ProgressImage.Width := ScaleX(200);
  ProgressImage.Height := ScaleY(20);
  ProgressImage.BackColor := clWhite;
  ProgressImage.Bitmap.Width := ProgressImage.Width;
  ProgressImage.Bitmap.Height := ProgressImage.Height;
end;

procedure DrawProgress(Image: TBitmapImage; Progress: Integer);
var
  Canvas: TCanvas;
  Width: Integer;
begin
  Log(Format('Drawing progress %d', [Progress]));
  
  Canvas := Image.Bitmap.Canvas;
  
  Canvas.Pen.Style := psClear;

  Width := Image.Bitmap.Width * Progress / 100
  Log(Format('Bar size: %d x %d', [Width, Image.Bitmap.Height]));

  Canvas.Brush.Color := clHighlight;
  Canvas.Rectangle(1, 1, Width, Image.Bitmap.Height);
  
  Canvas.Brush.Color := clBtnFace;
  Canvas.Rectangle(Width - 1, 1, Image.Bitmap.Width, Image.Bitmap.Height);

  Canvas.Pen.Style := psSolid;
  Canvas.Pen.Mode := pmCopy;
  Canvas.Pen.Color := clBlack;
  Canvas.Brush.Style := bsClear;
  Canvas.Rectangle(1, 1, Image.Bitmap.Width, Image.Bitmap.Height);
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  Log(Format('CurPageChanged %d', [CurPageID]));
  DrawProgress(ProgressImage, (CurPageID * 100 / wpFinished));
end;

Drawn progress bar


-1
投票

时间过去了很久,但我想分享一个解决方案,改变Inno Setup进度条的颜色以显示安装进度。我想这个解决方案可以应用于自定义进度条。经过一番谷歌搜索后,我提出了这个解决方案,但我没有更多参考资料来源。 附带说明:我没有卸载程序的解决方案。

  if CurPageID = wpInstalling then 
  begin
    Log('PAGE: wpInstalling ' + IntToStr(CurPageID));

    // Progress bar color cannot be changed from the application: request using Win DLL shall be done
    SendMessage(wizardform.progressgauge.Handle, PBM_SETBARCOLOR, 0, $DCA939); // Foreground color
    SendMessage(wizardform.progressgauge.Handle, PBM_SETBKCOLOR, 0, $202000);  // Background color
    //SendMessage(wizardform.progressgauge.Handle, PBM_SETMARQUEE, 1, 200);
  end;
© www.soinside.com 2019 - 2024. All rights reserved.