Search code examples
inno-setuppascalscript

Add image into the Inno Setup components list - component description


I would like to display a little image, when user hovers mouse cursor over a component on the "Select Components" page.

For example, I would like to do something like this:

enter image description here

I found a half solution here: Long descriptions on Inno Setup components.

But I'm missing the image part.


Solution

  • Building upon my answer to Long descriptions on Inno Setup components. You will need to copy HoverTimerProc and its supporting functions and global variables.

    This answer modifies the HoverComponentChanged and InitializeWizard procedures to support the images in addition to description labels.

    [Files]
    ...
    Source: Main.bmp; Flags: dontcopy
    Source: Additional.bmp; Flags: dontcopy
    Source: Help.bmp; Flags: dontcopy
    
    [Code]
    
    var
      CompLabel: TLabel;
      CompImage: TBitmapImage;
      LoadingImage: Boolean;
    
    procedure HoverComponentChanged(Item: Integer);
    var 
      Description: string;
      Image: string;
      ImagePath: string;
    begin
      case Item of
        0: begin Description := 'This is the description of Main Files'; Image := 'main.bmp'; end;
        1: begin Description := 'This is the description of Additional Files'; Image := 'additional.bmp'; end;
        2: begin Description := 'This is the description of Help Files'; Image := 'help.bmp'; end;
      else
        Description := 'Move your mouse over a component to see its description.';
      end;
      CompLabel.Caption := Description;
      
      if Image <> '' then
      begin
        // The ExtractTemporaryFile pumps the message queue, prevent recursion
        if not LoadingImage then
        begin
          LoadingImage := True;
          try
            ImagePath := ExpandConstant('{tmp}\' + Image);
            if not FileExists(ImagePath) then
            begin
              ExtractTemporaryFile(Image);
            end;
            CompImage.Bitmap.LoadFromFile(ImagePath);
          finally
            LoadingImage := False;
          end;
        end;
        CompImage.Visible := True;
      end
        else
      begin
        CompImage.Visible := False;
      end;
    end;
    
    procedure InitializeWizard();
    begin
      SetTimer(0, 0, 50, CreateCallback(@HoverTimerProc));
      
      CompImage := TBitmapImage.Create(WizardForm);
      CompImage.Parent := WizardForm.SelectComponentsPage;
      CompImage.Width := ScaleX(96);
      CompImage.Height := ScaleY(64);
      CompImage.Top :=
        WizardForm.ComponentsList.Top + WizardForm.ComponentsList.Height -
        CompImage.Height;
      CompImage.Left :=
        WizardForm.ComponentsList.Left + WizardForm.ComponentsList.Width -
        CompImage.Width;
      CompImage.Anchors := [akRight, akBottom];
    
      CompLabel := TLabel.Create(WizardForm);
      CompLabel.Parent := WizardForm.SelectComponentsPage;
      CompLabel.Left := WizardForm.ComponentsList.Left;
      CompLabel.Width := CompImage.Left - CompLabel.Left - ScaleX(16);
      CompLabel.Top := CompImage.Top;
      CompLabel.AutoSize := False;
      CompLabel.WordWrap := True;
      CompLabel.Anchors := [akLeft, akRight, akBottom];
      
      WizardForm.ComponentsList.Height :=
        WizardForm.ComponentsList.Height - CompImage.Height - ScaleY(8);
    end;
    

    enter image description here