使用Innosetup制作安装包的一些技巧

1. 选择安装界面上的图片

   [Setup]

   ;设置界面上的两个图片
   WizardImageFile=WizModernImage.bmp
   WizardSmallImageFile=WizSmallImage.bmp


2. 设置安装界面上的文字

   [Messages]
   ;设置开始界面
   WelcomeLabel1=%n欢迎安装 MyProgram开发系统
   WelcomeLabel2=%n集MyProgram于一体的开发平台%n%n-单机版:用于开发MyProgram功能平台%n%n-网络版:用于开发MyProgram功能平台%n%n%n%n%n
   ;设置许可证协议界面
   WizardLicense=许可证协议
   LicenseLabel=在安装“MyProgram开发系统”之前,请阅读%n授权协议
   ;设置安装路径选择界面
   WizardSelectDir=选择安装位置
   SelectDirDesc=选择“MyProgram开发系统”的安装文件夹
   SelectDirLabel3=-安装程序将安装 MyProgram开发系统 到下列文件夹%n%n-要安装到其他文件夹,单机[浏览(b)...]按钮并选择其他文件夹%n%n-点击[< 返回(B)]按钮返回上一个界面%n%n-选择[继续(N) >]按钮继续安装 MyProgram开发系统%n%n-选择[取消]按钮退出 MyProgram开发系统 安装
   SelectDirBrowseLabel=
   DiskSpaceMBLabel=
   ;设置组件安装界面
   WizardSelectComponents=选择组件
   SelectComponentsDesc=选择您想要安装的 MyProgram开发系统 的组件
   SelectComponentsLabel2=请选择您要安装的组件,清除您不想安装的组件。%n点击[继续(N) >]按钮继续。
   ;设置准备安装界面
   WizardReady=准备安装
   ReadyLabel1=安装程序将安装 MyProgram开发系统


3. 设置安装界面上的组件

  [Types]
  ;设置组件的两种状态,完全安装与用户自定义安装
  Name: "custom"; Description: "用户自定义安装"; Flags: iscustom
  Name: "full"; Description: "完全安装"

  [Components]
  ;默认为选择状态
  Name: "demo1"; Description: "demo1"; Types: full custom; Flags: fixed;
  ;默认为不选择状态,完全安装时为选择状态
  Name: "demo2"; Description: "demo2"; Types: full;
  ;默认为不选择状态
  Name: "demo3"; Description: "demo3"; Types: full;


4. 设置安装界面右上角图片大小及位置

   [Code]
   Var
      PageName, PageDescription: TLabel;

   {设置安装界面右上角图片大小及位置}
   procedure InitializeWizard();
   begin
     {WizardForm.WizardSmallBitmapImage.width := 100;
     WizardForm.WizardSmallBitmapImage.left := WizardForm.width - 100;
     WizardForm.WizardSmallBitmapImage.height := 50;
     WizardForm.PAGENAMELABEL.width:=100;
     WizardForm.PAGEDESCRIPTIONLABEL.width:=200;}
     PageName := TLabel.Create(WizardForm.MainPanel);
     PageName.Parent := WizardForm.MainPanel;
     PageName.Top := WizardForm.PageNameLabel.Top;
     PageName.Left := WizardForm.PageNameLabel.Left;
     PageName.Width := WizardForm.PageNameLabel.Width;
     PageName.Height := WizardForm.PageNameLabel.Height;
     PageName.Font := WizardForm.PageNameLabel.Font;
     PageName.Transparent := true;
     PageName.Font.Color:=clblack;

     PageDescription := TLabel.Create(WizardForm.MainPanel);
     PageDescription.Parent := WizardForm.MainPanel;
     PageDescription.Top := WizardForm.PageDescriptionLabel.Top;
     PageDescription.Left := WizardForm.PageDescriptionLabel.Left;
     PageDescription.Width := WizardForm.PageDescriptionLabel.Width;
     PageDescription.Height := WizardForm.PageDescriptionLabel.Height;
     PageDescription.Font := WizardForm.PageDescriptionLabel.Font;
     PageDescription.Transparent := true;
     PageDescription.Font.Color:=clblack;

     WizardForm.WizardSmallBitmapImage.Top := ScaleY(0);
     WizardForm.WizardSmallBitmapImage.Left := ScaleX(0);
     WizardForm.WizardSmallBitmapImage.Width := WizardForm.MainPanel.Width;
     WizardForm.WizardSmallBitmapImage.Height := WizardForm.MainPanel.Height;
     WizardForm.PageNameLabel.Visible := false;
     WizardForm.PageDescriptionLabel.Visible := false;
   end;

   procedure CurPageChanged(CurPageID: Integer);
   begin
     PageName.Caption := WizardForm.PageNameLabel.Caption;
     PageDescription.Caption := WizardForm.PageDescriptionLabel.Caption;
     PageDescription.width:=300;
   end;


5. 定义[Message]段颜色

   [code]
   procedure InitializeWizard();
   begin
      WizardForm.BeveledLabel.Enabled:= True;
      WizardForm.BeveledLabel.Font.Color:= clblue;

   end;


6. 安装、卸载时判断是否程序正在运行,卸载完成时自动打开网页

  1. [code]  
  2. var  
  3. ErrorCode: Integer;  
  4. IsRunning: Integer;  
  5. // 安装时判断客户端是否正在运行     
  6. function InitializeSetup(): Boolean;    
  7. begin    
  8. Result :=true//安装程序继续     
  9. IsRunning:=FindWindowByWindowName('东方宽频网络电视');    
  10. while IsRunning0 do    
  11. begin    
  12.     if Msgbox('安装程序检测到客户端正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNOthen    
  13.     begin    
  14.       Result :=false//安装程序退出     
  15.       IsRunning :=0;    
  16.     end else begin    
  17.       Result :=true//安装程序继续     
  18.       IsRunning:=FindWindowByWindowName('东方宽频网络电视');    
  19.     end;    
  20. end;    
  21. end;    
  22. // 卸载时判断客户端是否正在运行     
  23. function InitializeUninstall(): Boolean;    
  24. begin    
  25.    Result :=true//安装程序继续     
  26. IsRunning:=FindWindowByWindowName('东方宽频网络电视');    
  27. while IsRunning0 do    
  28. begin    
  29.     
  30.     if Msgbox('安装程序检测到客户端正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNOthen    
  31.     begin    
  32.       Result :=false//安装程序退出     
  33.       IsRunning :=0;    
  34.     end else begin    
  35.       Result :=true//安装程序继续     
  36.       IsRunning:=FindWindowByWindowName('东方宽频网络电视');      
  37.     end;    
  38. end;    
  39. end;    
  40. procedure CurUninstallStepChanged(CurUninstallStep:TUninstallStep);    
  41. begin    
  42. case CurUninstallStep of    
  43.     usUninstall:      
  44.       begin // 开始卸载     
  45.       end;    
  46.     usPostUninstall:    
  47.       begin      //卸载完成     
  48.         // MsgBox('CurUninstallStepChanged:'#13#13 'Uninstall just finished.', mbInformation, MB_OK);     
  49.         // ...insert code to performpost-uninstall tasks here...     
  50.         ShellExec('open','http://www.dreams8.com''''', SW_SHOWNORMAL, ewNoWait,ErrorCode);    
  51.       end;    
  52. end;    
  53. end;   

7. 去掉安装程序左上角“关于安装程序”的代码

  1. procedureInitializeWizard();  
  2. begin  
  3. WizardForm.BorderIcons:= [biMinimize];  
  4. end;  
  5. procedure CurPageChanged(CurPage: Integer);  
  6. begin  
  7. if CurPage=wpWelcome then  
  8. WizardForm.BorderIcons:= [biSystemMenu, biMinimize];  
  9. end;  
  10. 或者  
  11. procedure InitializeWizard();  
  12. begin  
  13. WizardForm.BORDERICONS := [biHelp, biSystemMenu, biMinimize];  
  14. end;   

8. 添加“关于”和网站链接按钮
  1. [Code]  
  2. procedure URLLabelOnClick(Sender: TObject);  
  3. var  
  4. ErrorCode: Integer;  
  5. begin  
  6. ShellExec('open''http://www.vistaqq.com''''', SW_SHOWNORMAL, ewNoWait,ErrorCode);  
  7. end;  
  8. procedure AboutButtonOnClick(Sender: TObject);  
  9. begin  
  10. MsgBox(#13 'Vista 状态条风格盘符' #13 #13'本软件由jinn制作,希望各位登陆中天VIP工作室!' #13#13 '版权所有 (C) 中天VIP工作室', mbInformation, MB_OK);  
  11. end;  
  12. var  
  13.     AboutButton, CancelButton: TButton;  
  14.     URLLabel: TNewStaticText;  
  15. procedure InitializeWizard();  
  16. begin  
  17. { Create the pages }  
  18. WizardForm.PAGENAMELABEL.Font.Color:= clred;  
  19. WizardForm.PAGEDESCRIPTIONLABEL.Font.Color:= clBlue;  
  20. WizardForm.WELCOMELABEL1.Font.Color:= clGreen;  
  21. WizardForm.WELCOMELABEL2.Font.Color:= clblack;  
  22.    CancelButton := WizardForm.CancelButton;  
  23.      AboutButton := TButton.Create(WizardForm);  
  24.      AboutButton.Left := WizardForm.ClientWidth -CancelButton.Left - CancelButton.Width;  
  25.      AboutButton.Top := CancelButton.Top;  
  26.      AboutButton.Width := CancelButton.Width;  
  27.      AboutButton.Height := CancelButton.Height;  
  28.      AboutButton.Caption := '&About';  
  29.      AboutButton.OnClick := @AboutButtonOnClick;  
  30.      AboutButton.Parent := WizardForm;  
  31. URLLabel := TNewStaticText.Create(WizardForm);  
  32.     URLLabel.Caption := '中天VIP工作室';  
  33.     URLLabel.Cursor := crHand;  
  34.     URLLabel.OnClick := @URLLabelOnClick;  
  35.     URLLabel.Parent := WizardForm;  
  36.     { Alter Font *after* setting Parent so the correctdefaults are inherited first }  
  37.     URLLabel.Font.Style := URLLabel.Font.Style +[fsUnderline];  
  38.     URLLabel.Font.Color := clBlue;  
  39.     URLLabel.Top := AboutButton.Top + AboutButton.Height -URLLabel.Height - 2;  
  40.     URLLabel.Left := AboutButton.Left + AboutButton.Width +ScaleX(20);  
  41. end;  

9. 安装时播放音乐

在脚本编译里的[Code]与[Files]段处添加以下代码:

[Code]
Function mciSendString(lpszCommand: String; lpszReturnString: Integer;cchReturnLength: Integer; hwndCallback: Integer): Integer;
external 'mciSendStringA@winmm.dll stdcall';


procedure InitializeWizard();
var
   BGMusicFile, SplashFile: string;
SplashForm: TForm;
SplashFileName: String;
I: Integer;
begin

ExtractTemporaryFile(ExtractFileName(ExpandConstant('{tmp}\music.mp3')));
SplashForm := TForm.create(nil);
with SplashForm do
   begin
mciSendString(ExpandConstant('play {tmp}\music.mp3'),0,0,0);
Close;
Free;
   end;
end;

[Files]
Source: "C:\music.mp3"; Flags: dontcopy

或者

Source: "C:\mymusic.mp3";DestDir: "{tmp}"; Flags: dontcopy

代码说明:[Code]中蓝色代码{tmp}与\music.mp3的意思是播放inno setup安装时创建的临时文件夹内的music.mp3音乐文件!

[Files]中C:\music.mp3是你音乐源文件的地址,填自己的音频名称与音频格式。Flags: dontcopy 的意思是在安装时将音乐文件放到Inno Setup所创建的临时文件夹内,并且在完成安装后删除此音乐文件


10. 关于Inno Setup安装欢迎界面文字与安装向导文字颜色修改

[Code]

procedure InitializeWizard();

begin

//改变欢迎页面文字的颜色 (如图)

WizardForm.WelcomeLabel1.Font.Color:= clNavy;

WizardForm.WelcomeLabel2.Font.Color:= clTeal;

end;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值