Inno Setup技巧[实例]添加自定义页面
通过“添加自定义页面”可以丰富安装程序的功能。本文以添加一个页面“选择安装类型”为例,选择标准安装将跳过“选择目标位置”和“选择开始菜单文件夹”两个页面。
在[Code]段添加以下代码:
var Page: TWizardPage; RadioButton1, RadioButton2: TRadioButton; Lbl1, Lbl2: TNewStaticText; procedure CreateAddonPage; begin Page := CreateCustomPage(wpInfoBefore, '选择安装类型', '请根据您的需要选择安装的类型'); RadioButton1 := TRadioButton.Create(Page); RadioButton1.Left := ScaleX(80); RadioButton1.Top := ScaleY(40); RadioButton1.Width := Page.SurfaceWidth; RadioButton1.Height := ScaleY(17); RadioButton1.Caption := '标准安装'; RadioButton1.Checked := True; RadioButton1.Parent := Page.Surface; Lbl1 := TNewStaticText.Create(Page); Lbl1.Left := ScaleX(95); Lbl1.Top := ScaleY(60); Lbl1.Width := ScaleX(250); Lbl1.Height := ScaleY(50); Lbl1.Caption := '按照标准模式安装软件到您的电脑'; Lbl1.Parent := Page.Surface; RadioButton2 := TRadioButton.Create(Page); RadioButton2.Left := ScaleX(80); RadioButton2.Top := RadioButton1.Top + ScaleY(60); RadioButton2.Width := Page.SurfaceWidth; RadioButton2.Height := ScaleY(17); RadioButton2.Caption := '自定义安装'; RadioButton2.Checked := false; RadioButton2.Parent := Page.Surface; Lbl2 := TNewStaticText.Create(Page); Lbl2.Left := ScaleX(95); Lbl2.Top := Lbl1.Top + ScaleY(60); Lbl2.Width := ScaleX(250); Lbl2.Height := ScaleY(50); Lbl2.Caption := '您可以选择单个安装项,建议经验丰富的用户使用'; Lbl2.Parent := Page.Surface; end; procedure InitializeWizard(); begin CreateAddonPage; end; function ShouldSkipPage(PageID: Integer): Boolean; begin if (PageID = wpSelectDir) and (RadioButton1.Checked) then Result := True else if (PageID = wpSelectProgramGroup) and (RadioButton1.Checked) then Result := True end;
代码中红色部分表示自定义页面所紧跟的向导页面的CurPageID值,蓝色部分分别表示自定义页面的标题和描述。
默认截图:
自定义截图:
转自:http://hi.baidu.com/watashi/item/b3dda993459ff8f0291647a0