inno setup - 基本脚本代码
; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!
#define MyAppName "Leawo Blu-ray Player"
#define MyAppVersion "1.0.0.0"
#define MyAppPublisher "moyea"
#define MyAppURL "https://www.example.com/"
#define MyAppExeName "leawo_player.exe"
;版本类型: 0--正式版, 1--CNET版本 2--德文版本 3--日语版
#define Brand "Leawo"
#define PrjType "bdplayer"
#define Language "ml"
;定义安装界面侧图
#define Background "BDPlayer.bmp"
[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (若要生成新的 GUID,可在菜单中点击 "工具|生成 GUID"。)
AppId={{08C4E9F8-34EB-4B81-BC68-352EACDBF79B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
;程序默认的安装路径
DefaultDirName=E:\Leawo\{#MyAppName}
DisableProgramGroupPage=yes
; 以下行取消注释,以在非管理安装模式下运行(仅为当前用户安装)。
;PrivilegesRequired=lowest
;app输出路径
OutputDir=C:\Users\moyea\Desktop\myapp
;输出的app名字
OutputBaseFilename=myapp_setup
SetupIconFile=C:\Users\moyea\Desktop\myapp\icon\BDPlayer.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl"; LicenseFile:C:\Users\moyea\Desktop\myapp\license\en\license.txt
Name: "zh"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"; LicenseFile:C:\Users\moyea\Desktop\myapp\license\zh\license.txt
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
//exe的路径
Source: "C:\Users\moyea\Desktop\myapp\app\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: release\core\*.*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs
Source: release\qt\*.*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs
Source: release\other\*.*; Excludes: language; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs
Source: release\other\language\*.*; DestDir: {app}\language; Flags: ignoreversion recursesubdirs createallsubdirs
;vs2013
Source: release\other\msvcr120.dll; DestDir: {sys}; Flags: onlyifdoesntexist ;
Source: release\other\msvcp120.dll; DestDir: {sys}; Flags: onlyifdoesntexist ;
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”
Source: image\{#Brand}\{#Language}\{#Background}; Flags: dontcopy
// 添加图片资源
Source: image\*.*; Flags: dontcopy
Source: image\InnoCallback.dll; DestDir: {app};Flags: dontcopy
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[Code]
var
WizardFormImage: TBitmapImage;//主界面的背景图
myPage: TwizardPage;
myBtn: TButton;
myLbl,myLbl2: TLabel;
MyButton: TNewButton;
MinimumBtn,MaxmumBtn,CloseBtn: TBitmapImage;
MyButton2: TNewButton;
MyBitmap: TBitmapImage;
BitmapImage: TBitmapImage;
ClickButton: TButton;
function ReleaseCapture(): Longint; external 'ReleaseCapture@user32.dll stdcall';
procedure ExitProcess(exitCode:integer);external 'ExitProcess@kernel32.dll stdcall';
procedure ClickmyBtn(Sender: TObject);
begin
myLbl2.Caption:='你点击了按钮~';
myLbl2.Color:=clRed;
end;
procedure ButtonClick(Sender: TObject);
begin
MsgBox('按钮2被点击了!', mbInformation, MB_OK);
end;
procedure ClickButtonClick(Sender: TObject);
begin
{ 处理点击事件 }
MsgBox('图片按钮被点击了!', mbInformation, MB_OK);
end;
//窗口关闭
procedure MyButtonClick(Sender: TObject);
begin
// 按钮点击事件处理
MsgBox('点击了关闭按钮!', mbInformation, MB_OK);
ExitProcess(0); // 关闭安装程序
end;
//窗口最小化
procedure MinimumBtnOnClick(Sender: TObject);
begin
SendMessage(WizardForm.Handle,$112,61472,0);
//window api SendMessage(绐楀彛鍙ユ焺,娑堟伅绫诲瀷WM_SYSCOMMAND,娑堟伅绫诲瀷鍙傛暟SC_CLOSE,0);
end;
//窗口移动
procedure WizardFormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture
SendMessage(WizardForm.Handle, $0112, $F012, 0);
end;
//在启动时使用该事件函数来改变向导或向导页面
procedure InitializeWizard();
var
MainLabel: TLabel;
szRegRoot,sTempFileName,strName: string;
bgColor: TColor; //背景图颜色
begin
#if 0
//创建一个自定义页面
myPage:=CreateCustomPage(wpWelcome, '标题:自定义页面', '描述:这是我的自定义页面');
//创建一个按钮1
myBtn:=TButton.Create(myPage);
myBtn.Parent:=myPage.Surface;
myBtn.Caption:='按钮1';
myBtn.OnClick:=@ClickmyBtn;
myBtn.Width := ScaleX(75);
myBtn.Height := ScaleY(23);
myBtn.Top := ScaleY(5);
myBtn.Left := ScaleX(3);
//创建一个标签
myLbl:=TLabel.Create(myPage);
myLbl.Parent:=myPage.Surface;
myLbl.Top:=myBtn.Top+50;
myLbl.Caption:='我是标签~';
myLbl.Width := ScaleX(75);
myLbl.Height := ScaleY(23);
//创建一个按钮2
MyButton := TNewButton.Create(myPage);
MyButton.Parent := myPage.Surface;
MyButton.Caption := '按钮2';
MyButton.OnClick := @ButtonClick;
MyButton.Width := ScaleX(75);
MyButton.Height := ScaleY(23);
MyButton.Top := ScaleY(115);
MyButton.Left := ScaleX(10);
#else
// 设置欢迎向导页的尺寸大小
WizardForm.OuterNotebook.hide; //隐藏默认的导向内容
WizardForm.Bevel.Hide; // 隐藏分隔线
WizardForm.BorderStyle:=bsnone; //去边框
WizardForm.Position:=poScreenCenter;// 位置屏幕居中
WizardForm.NextButton.Width:=0; // 隐藏下一步按钮
WizardForm.BackButton.Width:=0; // 隐藏跳过按钮
WizardForm.CancelButton.Width:=0; // 隐藏取消按钮
//WizardForm.Center;
WizardForm.Width:=650;
WizardForm.Height:=450;
WizardForm.Color:=clWhite; //白色
// WizardForm.InnerNotebook.Hide;
// WizardForm.Color:=TransparentColor; //透明颜色
//使用ExtractTemporaryFile函数来提取临时文件,这样在安装过程中可以访问到该文件。
//ExtractTemporaryFile('{src}\image\min.png');
//加载背景图片
WizardFormImage := TBitmapImage.Create(WizardForm);
WizardFormImage.Parent := WizardForm;
WizardFormImage.Align := alClient;
WizardFormImage.Bitmap.LoadFromFile(ExpandConstant('{src}\image\BDPlayerDown.bmp'));
WizardFormImage.Stretch := true;
//WizardFormImage.OnMouseDown:=@WizardFormMouseDown;
// 添加可以拖动窗口的Label,是个辅助label
MainLabel := TLabel.Create(WizardForm);
MainLabel.Parent := WizardForm;
MainLabel.AutoSize := False;
MainLabel.Left := 0;
MainLabel.Top := 0;
MainLabel.Width := WizardForm.Width;
MainLabel.Height := WizardForm.Height;
//MainLabel.Width := 50;
//MainLabel.Height := 50;
MainLabel.Caption := '我是一个可以拖动窗口的Label';
//MainLabel.Color := clRed;
MainLabel.Transparent := True; //设置成透明
MainLabel.OnMouseDown := @WizardFormMouseDown;
//创建一个标签
myLbl2:=TLabel.Create(WizardForm);
myLbl2.Parent:=WizardForm;
myLbl2.Top:=50;
myLbl2.Caption:='我是标签~';
myLbl2.Width := ScaleX(75);
myLbl2.Height := ScaleY(23);
//创建一个按钮1
myBtn:=TButton.Create(WizardForm);
myBtn.Parent:=WizardForm;
myBtn.Caption:='按钮1';
myBtn.OnClick:=@ClickmyBtn;
myBtn.Width := ScaleX(75);
myBtn.Height := ScaleY(23);
myBtn.Top := ScaleY(5);
myBtn.Left := ScaleX(3);
myBtn.Font.Color:=clRed
//按钮加载图片方式1:最小化按钮
MinimumBtn := TBitmapImage.Create(WizardForm);
MinimumBtn.Parent := WizardForm;
MinimumBtn.SetBounds(350, 0, 32, 32); // 设置图片的位置和大小
MinimumBtn.ShowHint := True;
MinimumBtn.Stretch := True;
//MinimumBtn.OnMouseDown := @MinimumBtnOnMouseDown;
//MinimumBtn.OnMouseUp := @MinimumBtnOnMouseUp;
//MinimumBtn.OnMouseEnter := @MinimumBtnOnMouseEnter;
//MinimumBtn.OnMouseLeave := @MinimumBtnOnMouseLeave;
MinimumBtn.OnClick:= @MinimumBtnOnClick;
MinimumBtn.Bitmap.LoadFromFile(ExpandConstant('{src}\image\min.bmp'));
//按钮加载图片方式2:关闭按钮
MyButton2 := TNewButton.Create(WizardForm);
MyButton2.Parent := WizardForm;
MyButton2.Left := 390;
MyButton2.Top := 0;
MyButton2.Width := 32;
MyButton2.Height := 32;
MyButton2.OnClick := @MyButtonClick;
MyButton2.Caption := '';
// 加载按钮图片
MyBitmap := TBitmapImage.Create(MyButton2);
MyBitmap.Parent := MyButton2;
MyBitmap.AutoSize := True;
MyBitmap.Stretch := True;
MyBitmap.Bitmap.LoadFromFile(ExpandConstant('{src}\image\close.bmp')); // 替换为你的图片路径
//按钮加载图片方式3
{ 创建 TBitmapImage 控件并加载图片 }
BitmapImage := TBitmapImage.Create(WizardForm);
BitmapImage.Parent := WizardForm;
BitmapImage.SetBounds(0, 80, 32, 32); { 设置合适的尺寸 }
BitmapImage.Bitmap.LoadFromFile(ExpandConstant('{src}\image\close.bmp'));
{ 创建 TButton 控件并设置其位置与 TBitmapImage 相同 }
ClickButton := TButton.Create(WizardForm);
ClickButton.Parent := WizardForm;
ClickButton.SetBounds(BitmapImage.Left, BitmapImage.Top, BitmapImage.Width, BitmapImage.Height);
ClickButton.OnClick := @ClickButtonClick; { 指定点击事件处理程序 }
ClickButton.Visible := True; { 不显示按钮本身 }
#endif
// 获取安装包名字
strName := ParamStr(0);//ParamStr返回传递给安装程序或卸载程序的命令行参数的索引,不包括安装程序和卸载程序使用的未记录的内部参数。参数编号为 0,是启动安装或卸载时的完整文件名。如果索引无效,ParamStr 将返回空字符串。
sTempFileName := ExtractFileName(strName); //ExtractFileName返回给定文件名的名称部分。如果 PathName 末尾带有反斜杠,则结果是一个空字串。
// 显示安装包名字
MsgBox('安装包名字是: ' + sTempFileName, mbInformation, MB_OK);
//注册表路径
szRegRoot := ExpandConstant('Software\Leawo Software\SoftwarePassport\' + 'Leawo Blu-ray Player' + '\0');
//写入注册表> 键:Version-Type 值:666
//路径:HKEY_CURRENT_USER\SOFTWARE\Leawo Software\SoftwarePassport\Leawo Blu-ray Player\0
RegWriteStringValue(HKEY_CURRENT_USER, szRegRoot, 'Version-Type', '666');
//写入注册表> 键:Version-Type 值:886
//路径:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Leawo Software\SoftwarePassport\Leawo Blu-ray Player\0
RegWriteStringValue(HKEY_LOCAL_MACHINE, szRegRoot, 'Version-Type', '886');
end;
注:添加拖动窗口的代码必须要在加载背景图片之后执行,否则会导致主界面的按钮点击后没反应。(原因是代码有先后执行的顺序),正常的代码执行顺序是:先贴背景图片,再添加可拖动的辅助label,最后添加按钮。
运行结果: