• Inno Setup添加自定义页面


    目的

    添加一个可以选中安装模式的自定义页面,如下图:
    

    快速安装模式: 跳过安装路径选择
    自定义安装模式:正常选择安装路径
    

    创建[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,该页面被显示。

  • 相关阅读:
    CMMI学习系列(1)CMMI简介及证书介绍
    Lync 2010 系统架构 学习笔记(2)
    Lync 2010 标准版 AD控制器搭建 学习笔记(3)
    云计算 学习笔记(4) HDFS 简介及体系结构
    云计算 学习笔记(1) Hadoop简介
    Lync 2010 Lync客户端测试 学习笔记(7)
    Lync 2010 监控服务器配置 学习笔记(8)
    CMMI学习系列(7)组织过程库,预评估,正式评估。
    CMMI学习系列(5)CMMI3过程规范制定
    CMMI学习系列(6)项目试点
  • 原文地址:https://www.cnblogs.com/zwbsoft/p/16152239.html
Copyright © 2020-2023  润新知