概述
- 使用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;
-
- 实现的页面效果如下