1

I create a progress bar using TNewProgressBar.
The default color of the progress bar is green.
I would like to change the color to blue.

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
yuval
  • 2,428
  • 4
  • 27
  • 42

2 Answers2

4

You cannot.


The progress bar is styled by the current Windows theme. In the default Windows theme, the progress bar is green (or yellow or red, if the progress bar is in paused or error state, see TNewProgressBar.State).

You would have to completely reimplement the drawing of the progress bar or disable visual themes of whole installer.
See How to change the color of progressbar in C# .NET 3.5?

But the Inno Setup API does not allow you to reimplement the drawing. And you probably do not want to disable the visual themes.


If you really need the blue color, you may consider implementing the progress bar yourself using TBitmapImage.Bitmap.Canvas (using methods like .Rectangle).

A simple example:

var
  ProgressImage: TBitmapImage;

procedure InitializeWizard();
begin
  ProgressImage := TBitmapImage.Create(WizardForm);
  ProgressImage.Parent := WizardForm;
  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

Community
  • 1
  • 1
Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
  • But when using TBitmapImage.Bitmap.Canvas will I be able to add animations to a progress bar? – yuval Nov 12 '15 at 09:49
  • You have to redraw the Bitmap everytime the progress changes. – Martin Prikryl Nov 12 '15 at 09:53
  • But I would like an animation to run on the progress bar even if the progress bar is stuck in the middle. Is their any way to do it with a gif? – yuval Nov 12 '15 at 10:12
  • Well, you can draw anything you want. As long as you have a control of the GUI thread at the time the lenghty operation runs. There's no support for animated GIFs in Inno Setup though. You would have to paint a BMP frames in intervals. – Martin Prikryl Nov 12 '15 at 10:27
  • 1
    Though your question was about blue progress bar. An animation is well beyond that. – Martin Prikryl Nov 12 '15 at 10:29
-1

Long time passed, but I would like to share a solution to change the color of the progress bar of Inno Setup for installation progress. I guess this solution can be applied to a custom progress bar. I put in place this solution after some googling, but I have no more reference to the sources. As a side note: I do not have a solution for the uninstaller.

  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;
AlSavi
  • 84
  • 5
  • Does not work for me. Maybe you can chare a complete solution, including the definitions of `PBM_SETBARCOLOR` and `PBM_SETBKCOLOR`. – Also, I do not understand what you mean by *"request using Win DLL"*. – Martin Prikryl Mar 25 '22 at 19:08