inno setup打包时自定义页面

概述

  • 使用inno setup制作的安装包,默认只有安装欢迎页,目录选择页、正在安装页和安装完成页。除此之外,inno setup还提供了一些其它安装页面,如许可协议展示页、用户信息输入页等,并且还支持自定义页面。本文章就具体介绍下如何设置这样自定义页面。

安装页面总览

  • inno setup脚本中提供了以下安装页面

    页面说明
    wpWelcome欢迎页
    wpLicense许可协议页
    wpPassword密码页
    wpInfoBefore信息页(安装之前)
    wpUserInfo用户信息页
    wpSelectDir安装目录选择页
    wpSelectComponents选择组件
    wpSelectProgramGroup选择开始菜单文件夹
    wpSelectTasks选择任务
    wpReady准备安装
    wpPreparing正在准备安装
    wpInstalling正在安装页
    wpInfoAfter信息页(安装之前)
    wpFinished安装完成页
  • 接下来就介绍下如何显示所有安装页面

  • 要显示对应页面,需要先在[code]段的ShouldSkipPage接口中指定返回值,返回True表示跳过该页面,返回False表示保留该页面。

    •   [code]
        function ShouldSkipPage(PageID : integer) : boolean;
        begin
          // 显示欢迎页
          if (PageID = wpWelcome) then Result := False;
          // 跳过许可协议页
          if (PageID = wpLicense) then Result := True;
        end;
      
  • 要显示对应页面,先在该接口中将对应返回值置为False。也可以不实现该函数,默认是页面都保留。但是手动实现,后续修改比较方便。

  • 接下来还需要配置不同的参数,才能将对应的安装页面显示出来,具体如下

欢迎页-wpWelcome

  • [setup]段将DisableWelcomePage置为no.
    •   [setup]
        DisableWelcomePage=no
      
    • 在这里插入图片描述

许可协议页-wpLicense

  • [setup]段给LicenseFile参数指定一个linces文本文件。在license.txt中写入要展示的许可协议即可。
    •   [setup]
        LicenseFile=.\input\license.txt	
      
    • 在这里插入图片描述

密码页-wpPassword

  • [code]段的CheckPassword接口中进行密码校验
    •   [code]
        function CheckPassword(Password: String): Boolean;
        begin
        	if Password='123456' then
        		result:=true;
        end;
      
    • 在这里插入图片描述

信息页(安装之前)-wpInfoBefore

  • [setup]段给InfoBeforeFile参数指定一个文本文件。
    •   [setup]
        InfoBeforeFile=.\input\infoBefore.txt
      
    • 在这里插入图片描述

用户信息页-wpUserInfo

  • [setup]段将UserInfoPage参数置为yes。可以在用户信息界面填写一些用户信息。
    •   [setup]
        UserInfoPage=yes
      
    • 在这里插入图片描述

安装目录选择页-wpSelectDir

  • 不需要再额外设置,需要注意的是,如果是覆盖安装,就不会出现安装目录选择页
    • 在这里插入图片描述

选择组件-wpSelectComponents

  • [file][Components]段对安装文件进行分类
    •   [Files]
        Source: ".\input\*"; DestDir: "{app}\innodlltest";Components:main
        Source: ".\input\platforms\*"; DestDir: "{app}\innodlltest\platforms";Components:main
        Source: ".\input\config\*"; DestDir: "{app}\innodlltest\config";Components:main
        Source: ".\data\*"; DestDir: "{app}\innodlltest\data";Components:data
        Source: ".\doc\*"; DestDir: "{app}\innodlltest\doc";Components:help
      
        [Components]
        Name: main; Description:"主程序(必选)";Types:full compact custom;Flags: fixed
        Name: data;Description:"数据文件";Types:full
        Name: help;Description:"帮助文档";Types:full
      
    • 在这里插入图片描述

准备安装页-wpReady

  • 不需要再额外设置。展示我们安装的一些配置。
    • 在这里插入图片描述

信息页(安装之后)-wpInfoAfter

  • [setup]段给InfoAfterFile参数指定一个文本文件。这个页面是在安装进度条结束后显示。
    •   [setup]
        InfoAfterFile=.\input\infoAfter.txt
      
    • 在这里插入图片描述

安装完成页-wpFinished

  • 不需要格外设置。这是安装的最后一个页面,点击完成后就安装结束,关闭安装界面。
    • 在这里插入图片描述

安装页面修改

  • inno setup脚本允许对安装界面进行修改,实现一些自定义的功能。比较常用是对欢迎页和用户信息输入页的修改。这里重点介绍下对这两个页面的修改,其它页面也可以进行修改,可以参考官方文档去设置。

欢迎页修改

  • 可以修改欢迎页的文字提示以及样式,示例如下
    •   procedure InitializeWizard();
        begin
          // 欢迎页自定义
          with WizardForm do
          begin
        	WelcomeLabel1.left := 280;
        	WelcomeLabel1.Width := 85;
        	WelcomeLabel1.Caption := '欢迎页';
        	WelcomeLabel1.Color := $87CEFA;
        	welcomeLabel1.Font.Size := 20;
        	WelcomeLabel1.Font.Name := '微软雅黑';
        	welcomeLabel1.Font.Color := $2F4F4F;
        	WelcomeLabel2.Caption := '欢迎使用inno setup';
        	WelcomeLabel2.Color := $CFCFCF;
        	welcomeLabel2.Font.Size := 10;
        	WelcomeLabel2.Font.Name := '微软雅黑';
        	welcomeLabel2.Font.Color := $2F4F4F;
          end;
        end;
      
  • 修改后页面如下
    • 在这里插入图片描述

用户信息页修改

  • 可以修改用户信息页的输入提示信息
    •   procedure InitializeWizard();
        var
          customUserInfoLabel: TLabel;
          customUserInfoEdit: TEdit;  
      
        begin
          // 用户信息页自定义
          with WizardForm do
          begin
        	UserInfoNameLabel.Caption := '请输入用户名';
        	UserInfoOrgLabel.Caption := '请输入组织名';
      
        	customUserInfoLabel:= TLabel.Create(WizardForm);  
        	customUserInfoLabel.parent:= USERINFONAMELABEL.parent;  
        	customUserInfoLabel.top:= USERINFONAMELABEL.top + 2 * (USERINFOORGLABEL.top - USERINFONAMELABEL.top);  
        	customUserInfoLabel.left:= USERINFOSERIALLABEL.left;  
        	customUserInfoLabel.autosize:= true;  
        	customUserInfoLabel.font.color:= clblack;  
        	customUserInfoLabel.caption:= '请输入序列号';
      
        	customUserInfoEdit:= TEdit.Create(WizardForm);  
        	customUserInfoEdit.parent:= USERINFONAMEEDIT.parent;  
        	customUserInfoEdit.top:= USERINFONAMEEDIT.top + 2 * (USERINFOORGEDIT.top - USERINFONAMEEDIT.top);  
        	customUserInfoEdit.left:= USERINFOSERIALEDIT.left;  
        	customUserInfoEdit.width:= USERINFOSERIALEDIT.width;  
        	customUserInfoEdit.readonly:= true;   
        	customUserInfoEdit.text := '123456789';
          end;
        end;
      
  • 页面如下
    • 在这里插入图片描述

自定义页面

  • inno setup允许自定义一个安装页面,需要用到以下接口。
    •   /*
        * AfterID: 表示该页面在哪个页面之后显示
        */
        function CreateCustomPage(const AfterID: Integer; const ACaption, ADescription: String): TWizardPage; 
      
  • 比如可以显示在欢迎页之后,可以在自定义页面上放置inno setup提供的组件,实现更多个性化的功能。
    •   [Code]
        var
        customPageCheckBox1, customPageCheckBox2: TCheckBox;
        customPageEdit: TEdit;
        
        customPageRadio1,customPageRadio2: TRadioButton;
        customPageRadioTitleLabel: TLabel;
        
        customPageListBox: TListBox;
        customPageListBoxTitleLabel: TLabel;
        
        customPageCheckListBox: TNewCheckListBox;
        customPageCheckListBoxLabel, customPageCheckListBoxTextLabel: TLabel;
        
        
        procedure customBtnClickCb(Sender: TObject);
        begin
          MsgBox('你点击了按钮~~', MBInformation, MB_OK);
        end;
        
        procedure customCheckBox1ClickCb(Sender:TObject);
        begin
          if customPageCheckBox1.Checked then
          begin
            customPageEdit.Text := customPageCheckBox1.Caption;
          end
          else
          begin
            customPageEdit.Text := 'cancel c++';
          end
        end;
        
        procedure customCheckBox2ClickCb(Sender:TObject);
        begin
          if customPageCheckBox2.Checked then
          begin
            customPageEdit.Text := customPageCheckBox2.Caption;
          end
          else
          begin
            customPageEdit.Text := 'cancel java';
          end
        end;
        
        procedure customRadio1ClickCb(Sender: TObject);
        begin
        	customPageRadioTitleLabel.Font.Color := clRed;
        end;
        
        procedure customRadio2ClickCb(Sender: TObject);
        begin
        	customPageRadioTitleLabel.Font.Color := clBlue;
        end;
        
        procedure customListBoxClickCb(Sender: TObject);
        begin
        	customPageListBoxTitleLabel.Caption := '列表, 请选择:' + customPageListBox.Items[customPageListBox.ItemIndex];
        end;
        
        procedure customCheckListBoxClickCb(Sender: TObject);
        var
          i: Integer;
        begin
          for i:=1 to 3 do
            if customPageCheckListBox.Checked[i] then
                customPageCheckListBoxTextLabel.Caption := customPageCheckListBox.ItemCaption[i] + '  ';   
            for i:=5 to 7 do
                if customPageCheckListBox.Checked[i] then
                    customPageCheckListBoxTextLabel.Caption := customPageCheckListBoxTextLabel.Caption + customPageCheckListBox.ItemCaption[i] + ' ';
        
        end;
        
        
        procedure myCreateCustomPage();
        var
          customPage: TwizardPage;
          customPageId: Integer; 
        
          customPageFont: TFont;
        
          customPageBtn: TButton; 
          customPageLabel: TLabel;
          
          customPageCheckBoxTitleLabel: TLabel;
        
          customPageTmemo: TMemo;
          
        begin
          customPage := CreateCustomPage(wpWelcome, '自定义页面', '自定义页面功能');
          customPageId := customPage.ID;
        
          // 按钮
          customPageBtn := TButton.Create(customPage);
          customPageBtn.Parent := customPage.Surface;
          customPageBtn.Caption := '按钮';
          customPageBtn.Default := True;
          customPageFont := TFont.Create();
          customPageFont.Size := 14;
          customPageFont.Color := $87CEFA;
          customPageBtn.Font := customPageFont;
          customPageBtn.Width := 50;
          customPageBtn.Height := 35;
          customPageBtn.OnClick := @customBtnClickCb;
        
          // 标签
          customPageLabel := TLabel.Create(customPage);
          customPageLabel.Parent := customPage.Surface;
          customPageFont := TFont.Create();
          customPageFont.Size := 14;
          customPageLabel.Font := customPageFont;
          customPageLabel.Top := 50;
          customPageLabel.Caption:='标签';
        
          // 编辑框
          customPageEdit := TEdit.Create(customPage);
          customPageEdit.Parent := customPage.Surface;
          customPageEdit.Top := 90;
          customPageEdit.Width := 60;
          customPageEdit.Height := 30;
          customPageEdit.Text := 'hello world';
        
          // 复选框
          customPageCheckBoxTitleLabel := TLabel.Create(customPage);
          customPageCheckBoxTitleLabel.Parent:=customPage.Surface;
          customPageCheckBoxTitleLabel.Top := 140;
          customPageCheckBoxTitleLabel.Caption:='复选按钮, 请选择:';
          
          customPageCheckBox1:= TCheckBox.Create(customPage);
          customPageCheckBox1.Parent:=customPage.Surface;
          customPageCheckBox1.Caption:='C++';
          customPageCheckBox1.top:= 160;
          customPageCheckBox1.OnClick:=@customCheckBox1ClickCb;
        
          customPageCheckBox2:= TCheckBox.Create(customPage);
          customPageCheckBox2.Parent:=customPage.Surface;
          customPageCheckBox2.Caption:='Java';
          customPageCheckBox2.top:= 180;
          customPageCheckBox2.OnClick:=@customCheckBox2ClickCb;
        
          // 单选框
          customPageRadioTitleLabel := TLabel.Create(customPage);
          customPageRadioTitleLabel.Parent := customPage.Surface;
          customPageRadioTitleLabel.Top := 10;
          customPageRadioTitleLabel.Left := 100;
          customPageRadioTitleLabel.Caption := '单选按钮, 请选择:';
        
          customPageRadio1 := TRadioButton.Create(customPage);
        	customPageRadio1.Parent := customPage.Surface;
        	customPageRadio1.Caption := '红色';
        	customPageRadio1.Top := 30;
          customPageRadio1.Left := 100;
        	customPageFont := TFont.Create();
        	customPageFont.Color := clRed;
        	customPageRadio1.Font := customPageFont;
        	customPageRadio1.OnClick:=@customRadio1ClickCb;
        
          customPageRadio2 := TRadioButton.Create(customPage);
        	customPageRadio2.Parent := customPage.Surface;
        	customPageRadio2.Caption := '蓝色';
        	customPageRadio2.Top := 50;
          customPageRadio2.Left := 100;
        	customPageFont := TFont.Create();
        	customPageFont.Color := clBlue;
        	customPageRadio2.Font := customPageFont;
        	customPageRadio2.OnClick:=@customRadio2ClickCb;
        
          // 多行编辑框
          customPageTmemo := TMemo.Create(customPage);
        	customPageTmemo.Parent := customPage.Surface;
          customPageTmemo.Top := 80;
          customPageTmemo.Left := 100;
          customPageTmemo.Width := 140;
          customPageTmemo.Height := 60;
          customPageTmemo.WordWrap:=True;         // 自动换行
        	customPageTmemo.WantTabs:=True;         // 接受Tab键
        	customPageTmemo.WantReturns:=True;      // 换行
          customPageTmemo.ScrollBars:=ssVertical; // 滚动条
        
          customPageTmemo.Text:='文本开始显示';
        	customPageTmemo.Lines.Add('添加一行新文本');
        	customPageTmemo.Lines.Insert(0,'插到最前面');
          customPageTmemo.Lines.Add('这一行可以删除');
        	customPageTmemo.Lines.Delete(3);
          customPageTmemo.Lines.Add('这是最后一行');
        
        
          // 列表
          customPageListBoxTitleLabel := TLabel.Create(customPage);
          customPageListBoxTitleLabel.Parent := customPage.Surface;
          customPageListBoxTitleLabel.Top := 150;
          customPageListBoxTitleLabel.Left := 100;
          customPageListBoxTitleLabel.Caption := '列表, 请选择:';
        
          customPageListBox := TListBox.Create(customPage);
        	customPageListBox.Parent := customPage.Surface;
          customPageListBox.Top := 170;
          customPageListBox.Left := 100;
          customPageListBox.Height := 60;
          customPageListBox.Items.Add('程序');
          customPageListBox.Items.Add('数据');
          customPageListBox.Items.Add('文档');
          customPageListBox.OnClick:=@customListBoxClickCb;
        
          // 多组件选择
          customPageCheckListBoxLabel := TLabel.Create(customPage);
          customPageCheckListBoxLabel.Parent := customPage.Surface;
          customPageCheckListBoxLabel.Top := 10;
          customPageCheckListBoxLabel.Left := 240;
          customPageCheckListBoxLabel.Caption := '选择组件:';
        
          customPageCheckListBoxTextLabel := TLabel.Create(customPage);
          customPageCheckListBoxTextLabel.Parent := customPage.Surface;
          customPageCheckListBoxTextLabel.Top := 30;
          customPageCheckListBoxTextLabel.Left := 240;
        
          customPageCheckListBox := TNewCheckListBox.Create(customPage);
          customPageCheckListBox.Parent := customPage.Surface;
        
          customPageCheckListBox.Width := 140;
          customPageCheckListBox.Top := 50;
          customPageCheckListBox.Left := 260;
          customPageCheckListBox.Height := ScaleY(160);
          customPageCheckListBox.Flat := True;
          customPageCheckListBox.AddCheckBox('操作系统', '', 0, True, True, False, True, nil);
          customPageCheckListBox.AddRadioButton('Windows 7', '', 1, False, True, nil);
          customPageCheckListBox.AddRadioButton('Windows 10', '', 1, True, True, nil);
          customPageCheckListBox.AddRadioButton('Windows 11', '', 1, False, True, nil);
          customPageCheckListBox.AddCheckBox('可安装组件', '', 0, True, True, False, True, nil);
          customPageCheckListBox.AddCheckBox('QtCode', '', 1, True, True, False, True, nil);
          customPageCheckListBox.AddCheckBox('QtGui', '', 1, True, True, False, True, nil);
          customPageCheckListBox.AddCheckBox('QtNetwork', '', 1, False, True, False, True, nil);
          customPageCheckListBox.OnClickCheck:=@customCheckListBoxClickCb;   
        
        end;	
      
        procedure InitializeWizard();
        // 自定义页面
        myCreateCustomPage();
        end;
      
  • 实现的页面效果如下
    • 在这里插入图片描述
### 回答1: InnoSetup是一个易于使用的安装包制作工具,它提供了丰富的安装选项和自定义功能。在使用InnoSetup制作安装,我们可以通过自定义安装界面来满足客户的各种需求。 通过InnoSetup的宏命令和脚本语言,我们可以轻松地修改默认的安装界面,例如添加自定义控件、更改按钮文本、更改字体和颜色等。可以使用Pascal脚本和Delphi Object Pascal语言。 要自定义安装界面,我们需要首先打开InnoSetup的脚本文件(.iss文件)并找到“[Setup]”部分。在这里,我们可以设置安装程序的各种选项,例如安装的目标路径、是否需要安装桌面快捷方式、是否需要安装开始菜单项等等。 然后,我们可以添加新的页面自定义控件,例如选择安装选项的页面、选择安装路径的页面、选择应用程序图标的页面等等。我们可以使用InnoSetup自带的控件,也可以使用自定义控件来实现更复杂的功能。 最后,我们可以为每个页面添加Pascal脚本来实现自定义逻辑,例如检查安装目录是否已存在、检查系统是否已安装必要的组件等等。 总之,InnoSetup提供了灵活的自定义安装界面功能,让我们可以满足不同客户的需求,并提高软件的用户体验。 ### 回答2: Inno Setup 可以在安装过程中自定义安装界面,使其更符合特定的软件需求和个性化需求。通过自定义安装界面,可以加强用户交互体验,提高软件的可用性和易用性,同也可以为软件提供更精细的管理和控制。下面将分别从设计理念、开发流程和技术实现方面进行介绍。 设计理念 Inno Setup自定义安装界面开发过程,从本质上来说是一次用户交互设计 (User Experience Design, UXD) 的过程。通过 UXD,设计师可以了解客户的需求、喜好和习惯,进而设计出更符合其需求的产品和服务。在自定义安装界面开发流程中,设计师需要考虑以下几个方面: 1. 界面设计。界面设计应该简单明了、美观大方,能够吸引用户的注意力并提高用户的参与度。同需要考虑不同用户的操作习惯和口味,以达到更广泛的用户群体。 2. 用户体验 (User Experience, UX) 设计。在设计界面,需要考虑到用户的体验。例如:简化繁琐的操作、提供更多的选择、给予良好的反馈等都是好的用户体验设计。 3. 交互设计。特别是在软件界面方面,设计师需要思考用户将与之如何交互,如何设定第一间与其进行沟通交流。 开发流程 在设计理念上确定了之后,我们需要有一个中间人对需求进行保存和整理。通常情况下需要特别有经验的的开发人员还需要具备美工能力,能够从业务流程到界面交互再到发布之间都能够进行系统性的构建和实践。 首先,需要准备安装向导的图片资源、控件资源等基本素材,并制定对应的管理策略。然后在1.4版本以上的 Inno Setup 中,我们可以手动复制 Setup 向导的默认源文件,再进行相应的更改即可。 接着,需要使用 Pascal 编写脚本来确保安装向导能够正确检测到用户的操作,以及完成相应的安装任务。同,还需要定义安装向导的菜单项、默认值、文件读取方式等,以方便用户进行自定义设置和个性化操作。 最后,在整个自定义安装界面开发完成后,我们需要使用 Inno Setup 自带的编译器工具将代码打包并生成可供安装安装包,从而方便用户进行安装和使用。 技术实现方案 实现自定义安装界面的技术方案主要分为以下几个方面: 1. 界面设计工具。可以选择比较流行的界面设计工具,如 Adobe Photoshop,Axure RP,Sketch 等,这些工具都具有快速地设计复杂界面的能力。 2. 编程语言。Inno Setup 采用 Pascal 语言编写,因此需要对 Pascal 语言有一定的了解和掌握基本的编程技能。 3. Inno Setup 插件。InnoSetup 提供了一系列插件,可以方便我们在安装向导中引入大量有用的功能,如申请服务权限、加密等。 需要注意的是,Inno Setup 自定义安装界面开发风格应该以简单、实用、易于维护为原则,在设计需要注意不要过于复杂和繁琐,以方便用户进行快速的操作和安装。 ### 回答3: Inno Setup是一款功能强大的安装程序制作软件,它可以帮助开发者快速的制作出安装程序。而自定义安装界面则是Inno Setup所提供的一个很实用的功能之一,它可以使得开发者可以自由的设计自己的安装界面,让用户有一个更加舒适的安装体验。 首先,我们需要了解Inno Setup自定义安装界面的实现方式。整个安装过程中,Inno Setup会按照一定的流程逐步展示各个界面,在每一个界面上,开发者都可以通过界面的设计和编写代码来进行自定义。 在设计安装界面,我们可以使用Inno Setup自带的画布工具或者其他画图工具来设计出自己喜欢的安装界面,然后通过Inno Setup的代码来添加各种控件和事件。例如,我们可以添加各种按钮、文本框、进度条、复选框等控件,并通过代码来控制它们的显示和行为。 接下来,我们需要考虑自定义安装界面需要实现哪些功能。例如,我们可能需要在安装界面中添加自己的公司Logo、版本号、安装路径等信息,或者添加一些用户需要填写的信息,比如用户的名称、电子邮件和密码等。如果需要,我们也可以添加自己的安装协议和许可协议,并让用户需要点击同意才能继续安装。 总的来说,Inno Setup自定义安装界面功能非常强大,可以让开发者灵活的设计和实现自己的安装界面。但是需要注意的是,设计一个良好的安装界面需要考虑到用户的体验和操作方式,所以我们需要仔细考虑每一个控件的设计和布局,让用户能够尽可能的了解整个安装过程,并且保持简洁和易于操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大草原的小灰灰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值