ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Inno Setup添加自定义页面

2022-04-16 11:33:30  阅读:160  来源: 互联网

标签:自定义 Setup Lbl1 modePage RadioButton2 RadioButton1 Inno 安装 页面


目的

添加一个可以选中安装模式的自定义页面,如下图:
![](https://www.icode9.com/i/l/?n=22&i=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,该页面被显示。

标签:自定义,Setup,Lbl1,modePage,RadioButton2,RadioButton1,Inno,安装,页面
来源: https://www.cnblogs.com/zwbsoft/p/16152239.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有