代码之家  ›  专栏  ›  技术社区  ›  Robert Wigley

Inno安装程序在自定义表单标题栏上使用不同的图标

  •  1
  • Robert Wigley  · 技术社区  · 6 年前

    默认情况下,自定义窗体在标题栏中使用与主窗体相同的图标 WizardForm ,这是 SetupIconFile

    [Code]
    var
      CustomWindowForm: TForm;
    
    { Create and show the Custom window }
    procedure ShowCustomWindow();
    begin
      CustomWindowForm := TForm.Create(WizardForm);
      with CustomWindowForm do
        begin
          BorderStyle := bsSingle;
          Position := poOwnerFormCenter;
          Caption := 'Window Title';
          ClientWidth := ScaleX(400);
          ClientHeight := ScaleY(400);
          Show;
        end;
    end;
    

    Icon TForm ,但似乎没有,我在任何地方都找不到任何有关这方面的信息。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Martin Prikryl    5 年前

    您必须使用WinAPI,尤其是 LoadImage function WM_SETICON message :

    [Files]
    Source: "custom.ico"; Flags: dontcopy
    
    [Code]
    
    const
      IMAGE_ICON = 1;
      LR_LOADFROMFILE = $10;
      WM_SETICON = $80;
      ICON_SMALL = 0;
    
    function LoadImage(
      hInst: Integer; ImageName: string; ImageType: UINT; X, Y: Integer;
      Flags: UINT): THandle; external 'LoadImageW@User32.dll stdcall';
    
    procedure CustomFormShow(Sender: TObject);
    var
      Icon: THandle;
    begin
      ExtractTemporaryFile('custom.ico');
      Icon := LoadImage(
        0, ExpandConstant('{tmp}\custom.ico'), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
      SendMessage(TForm(Sender).Handle, WM_SETICON, ICON_SMALL, Icon);
    end;
    
    var
      CustomWindowForm: TForm;
    
    { Create and show the custom window }
    procedure ShowCustomWindow();
    begin
      CustomWindowForm := TForm.Create(WizardForm);
      with CustomWindowForm do
      begin
        { your code }
    
        OnShow := @CustomFormShow;
        Show;
      end;
    end;
    

    enter image description here