Inno Setup新增自定義頁面
阿新 • • 發佈:2022-04-16
目的
新增一個可以選中安裝模式的自定義頁面,如下圖:
![](https://img2022.cnblogs.com/blog/2022968/202204/2022968-20220416111449584-1936790099.png)
簡易模式: 跳過安裝路徑選擇
自定義模式:正常選擇安裝路徑
建立[Code]區段
-
[Code] 區段是一個指定Pascal指令碼的可選區段。Pascal指令碼可用於以多種方式自定義安裝程式或解除安裝。請注意,建立 Pascal 指令碼並不容易,需要具備 Inno Setup 的經驗以及有關 Pascal 程式設計或至少類似程式語言的知識。
-
[Code] 區程式碼:
[Code] //#########################安裝模式視窗屬性########################### var //模式選擇視窗 modePage:TwizardPage; //模式選擇視窗ID modePageID:Integer; //單選按鈕 RadioButton1, RadioButton2: TRadioButton; //標題 Lbl1, Lbl2: TNewStaticText; //#################################################################### //######################建立安裝模式選擇頁面########################## procedure CreateModPage; begin modePage := CreateCustomPage(wpInfoBefore, '選擇安裝型別', '請根據您的需要選擇安裝的型別'); modePageID:= modePage.ID; RadioButton1 := TRadioButton.Create(modePage); RadioButton1.Left := ScaleX(80); RadioButton1.Top := ScaleY(40); RadioButton1.Width := modePage.SurfaceWidth; RadioButton1.Height := ScaleY(17); RadioButton1.Caption := '快速安裝'; RadioButton1.Checked := True; RadioButton1.Parent := modePage.Surface; Lbl1 := TNewStaticText.Create(modePage); Lbl1.Left := ScaleX(95); Lbl1.Top := ScaleY(60); Lbl1.Width := ScaleX(250); Lbl1.Height := ScaleY(50); Lbl1.Caption := '按照簡易模式安裝軟體到您的電腦'; Lbl1.Parent := modePage.Surface; RadioButton2 := TRadioButton.Create(modePage); RadioButton2.Left := ScaleX(80); RadioButton2.Top := RadioButton1.Top + ScaleY(60); RadioButton2.Width := modePage.SurfaceWidth; RadioButton2.Height := ScaleY(17); RadioButton2.Caption := '自定義安裝'; RadioButton2.Checked := false; RadioButton2.Parent := modePage.Surface; Lbl2 := TNewStaticText.Create(modePage); Lbl2.Left := ScaleX(95); Lbl2.Top := Lbl1.Top + ScaleY(60); Lbl2.Width := ScaleX(250); Lbl2.Height := ScaleY(50); Lbl2.Caption := '您可以手動配置安裝目錄'; Lbl2.Parent := modePage.Surface; end; //################################################################### //##############################初始化引導視窗####################### procedure InitializeWizard(); begin //建立模式選擇頁面 CreateModPage; end; //################################################################### //#############################滿足條件跳過視窗###################### function ShouldSkipPage(PageID: Integer): Boolean; var selectPage: TwizardPage; begin Result := False; if RadioButton1.Checked then begin case PageID of //路徑選擇頁面 wpSelectDir: Result := True; end; end; end; //#####################################################################
-
部分方法解釋
-
嚮導頁面(頁面ID對應意思):
欄位 說明 wpWelcome 歡迎頁 wpLicense 許可協議 wpPassword 密碼 wpInfoBefore 資訊 wpUserInfo 使用者資訊 wpSelectDir 選擇目標位置 wpSelectComponents 選擇元件 wpSelectProgramGroup 選擇開始選單資料夾 wpSelectTasks 選擇任務 wpReady 準備安裝 wpPreparing 正在準備安裝 wpInstalling 正在安裝 wpInfoAfter 資訊 wpFinished 安裝完成 -
InitializeWizard:
procedure InitializeWizard();
在啟動時使用該事件函式來改變嚮導或嚮導頁面。你不能在它被觸發時使用 InitializeSetup 事件函式,因為嚮導窗體尚不存在。
-
CreateCustomPage:
function CreateCustomPage(const AfterID: Integer; const ACaption, ADescription: String): TWizardPage;
建立一個自定義嚮導頁面。這個頁面預設是空的;你可以建立自己的控制元件,然後放置到頁面中(通過設定它們的上級屬性為由這個函式返回的 TWizardPage 介面屬性例項)。
引數:
AfterID: 在哪個頁面ID之前顯示
ACaption: 說明文字
ADescription:詳細描述 -
ShouldSkipPage:
function ShouldSkipPage(PageID: Integer): Boolean;
嚮導呼叫這個事件函式確定是否在所有頁面或不在一個特殊頁面(用 PageID 指定)顯示。如果返回 True,將跳過該頁面;如果你返回 False,該頁面被顯示。
-