Inno Setuo 创建闪屏和背景音乐
NSIS 插件 advsplash.dll 现在有了进一步的更新,新插件的名称为 newadvsplash.dll,新的插件支持 bmp、gif 和 jpg 图像作为闪屏,闪屏可透明。背景音乐可以为 wav 和 mp3 格式,可循环播放。原则上使用该 NSIS 插件就可以制作带闪屏和背景音乐的 INNO 安装程序了,但是该插件播放音乐的功能有个欠缺,就是不能暂停播放。
因此推荐另外一个功能更强的音乐播放插件 BASSMOD.DLL,用该插件可以播放压缩率高音质高的 MOD 格式音乐文件,且支持暂停等功能。
; INNO SETUP 脚本文件
; 该示例脚本创建带闪屏和背景音乐的安装程序
; 使用了:
; - restools 的调用 NSIS 插件的通用插件 CallNSIS.DLL,详见 http://bbs.hanzify.org/read.php?tid=38694
; - 用于添加闪屏和背景音乐的 NSIS 插件 NewAdvSplash.DLL,详见 http://nsis.sourceforge.net/NewAdvSplash_plug-in
; - 播放 MOD 音乐的插件 BASSMOD.DLL,详见 http://un4seen.com/bassmod.html
;
; 汉化新世纪 gnatix,2006.9.8
AppName=我的程序
AppVerName=我的程序 1.5 版本
DefaultDirName={pf}我的程序
DefaultGroupName=我的程序
; 打包实现闪屏和背景音乐所必需的插件文件
Source: "Z:NSISADDINcallnsis.dll"; DestDir: "{tmp}"; Flags: dontcopy
Source: "Z:NSISADDINNewAdvSplash.dll"; DestDir: "{tmp}"; Flags: dontcopy
Source: "Z:NSISADDINBassmod.dll"; DestDir: "{tmp}"; Flags: dontcopy
; 打包闪屏和背景音乐素材文件:闪屏图像文件 bmp、gif 或者 jpg 格式, 音乐文件 MOD 格式
Source: "Z:NSISADDINsplash.gif"; DestDir: "{tmp}"; Flags: dontcopy
Source: "Z:NSISADDINmymusic.mod"; DestDir: "{tmp}"; Flags: dontcopy
; 以下打包软件本身的文件
; 请自己加上
; 以下是安装脚本的其它段代码
; 请自己加上
var
AboutButton: TButton;
MusicSwitchLabel0, MusicSwitchLabel1, MusicSwitchLabel2: TNewStaticText;
// 以下是所调用的插件函数
function BASSMOD_Init(device: Integer; freq, flags: DWORD): Boolean;
external 'BASSMOD_Init@files:BASSMOD.dll stdcall delayload';
procedure BASSMOD_MusicFree();
external 'BASSMOD_MusicFree@files:BASSMOD.dll stdcall delayload';
function BASSMOD_MusicLoad(mem: BOOL; f: PChar; offset: DWORD; length: DWORD; flags: DWORD): Boolean;
external 'BASSMOD_MusicLoad@files:BASSMOD.dll stdcall delayload';
function BASSMOD_MusicPlay(): Boolean;
external 'BASSMOD_MusicPlay@files:BASSMOD.dll stdcall delayload';
function BASSMOD_MusicPause(): Boolean;
external 'BASSMOD_MusicPause@files:BASSMOD.dll stdcall delayload';
procedure BASSMOD_Free();
external 'BASSMOD_Free@files:BASSMOD.dll stdcall delayload';
procedure callplug(parentwnd: Integer; pluginname,funcname,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10: PChar);
external 'callplug@files:callnsis.dll stdcall delayload';
// 以下是点击“关于”按钮后的响应函数
procedure AboutButtonOnClick(Sender: TObject);
begin
MsgBox('这是你的信息。'#13#10'这是你的信息的第二行。', mbInformation, MB_OK);
end;
// 以下是点击“打开音乐”按钮后的响应函数
procedure MusicSwitchLabel1OnClick(Sender: TObject);
begin
BASSMOD_MusicPlay;
MusicSwitchLabel1.Font.Color := clGray;
MusicSwitchLabel2.Font.Color := clBlue;
end;
// 以下是点击“关闭音乐”按钮后的响应函数
procedure MusicSwitchLabel2OnClick(Sender: TObject);
begin
BASSMOD_MusicPause;
MusicSwitchLabel2.Font.Color := clGray;
MusicSwitchLabel1.Font.Color := clBlue;
end;
// 安装向导初始化函数
procedure InitializeWizard();
var
BGMusicFile, SplashFile: string;
begin
// 创建“关于”按钮
AboutButton := TButton.Create(WizardForm);
AboutButton.Left := WizardForm.ClientWidth - WizardForm.CancelButton.Left - WizardForm.CancelButton.Width;
AboutButton.Top := WizardForm.CancelButton.Top;
AboutButton.Width := WizardForm.CancelButton.Width;
AboutButton.Height := WizardForm.CancelButton.Height;
AboutButton.Caption := '关于(&A)...';
AboutButton.OnClick := @AboutButtonOnClick;
AboutButton.Parent := WizardForm;
// 创建文字标签“音乐:”
MusicSwitchLabel0 := TNewStaticText.Create(WizardForm);
MusicSwitchLabel0.Left := AboutButton.Left + ScaleX(90);
MusicSwitchLabel0.Top := WizardForm.CancelButton.Top + ScaleY(3);
MusicSwitchLabel0.Width := ScaleX(30);
MusicSwitchLabel0.Height := ScaleY(12);
MusicSwitchLabel0.Font.Color := clRed;
MusicSwitchLabel0.Caption := '音乐:';
MusicSwitchLabel0.Parent := WizardForm;
// 创建文字标签作为“打开音乐”按钮(采用 Webdings 字体中的播放符号)
MusicSwitchLabel1 := TNewStaticText.Create(WizardForm);
MusicSwitchLabel1.Left := MusicSwitchLabel0.Left + ScaleX(33);
MusicSwitchLabel1.Top := MusicSwitchLabel0.Top - ScaleY(3);
MusicSwitchLabel1.Width := ScaleX(20);
MusicSwitchLabel1.Height := ScaleY(12);
MusicSwitchLabel1.Font.Color := clGray;
MusicSwitchLabel1.Font.Name := 'webdings';
MusicSwitchLabel1.Font.Size := -15;
MusicSwitchLabel1.Cursor := crCross;
MusicSwitchLabel1.Caption := #52
MusicSwitchLabel1.ShowHint:= true;
MusicSwitchLabel1.Hint:= '打开音乐';
MusicSwitchLabel1.OnClick := @MusicSwitchLabel1OnClick;
MusicSwitchLabel1.Parent := WizardForm;
// 创建文字标签作为“关闭音乐”按钮(采用 Webdings 字体中的暂停符号)
MusicSwitchLabel2 := TNewStaticText.Create(WizardForm);
MusicSwitchLabel2.Left := MusicSwitchLabel1.Left + ScaleX(20);
MusicSwitchLabel2.Top := MusicSwitchLabel0.Top - ScaleY(3);
MusicSwitchLabel2.Width := ScaleX(20);
MusicSwitchLabel2.Height := ScaleY(12);
MusicSwitchLabel2.Font.Color := clBlue;
MusicSwitchLabel2.Font.Name := 'webdings';
MusicSwitchLabel2.Font.Size := -15;
MusicSwitchLabel2.Cursor := crCross;
MusicSwitchLabel2.Caption := #59
MusicSwitchLabel2.ShowHint:= true;
MusicSwitchLabel2.Hint:= '关闭音乐';
MusicSwitchLabel2.OnClick := @MusicSwitchLabel2OnClick;
MusicSwitchLabel2.Parent := WizardForm;
// 释放临时文件
ExtractTemporaryFile(ExpandConstant('BASSMOD.dll'));
ExtractTemporaryFile(ExpandConstant('CallNSIS.DLL'));
ExtractTemporaryFile(ExpandConstant('NewAdvSplash.DLL'));
ExtractTemporaryFile(ExpandConstant('mymusic.mod'));
ExtractTemporaryFile(ExpandConstant('splash.gif'));
BGMusicFile := ExpandConstant('{tmp}mymusic.mod');
SplashFile := ExpandConstant('{tmp}splash.gif');
// 播放背景音乐
if not BASSMOD_Init(-1,44100,0) then
BASSMOD_Free;
BASSMOD_MusicFree;
if BASSMOD_MusicLoad(false, PChar(BGMusicFile), 0, 0, 4) then
BASSMOD_MusicPlay;
// 闪屏:显示时间 1600、淡入 800、淡出 500、透明颜色 -2 (表示 gif 图像本身透明)
CALLPLUG(0,ExpandConstant('{tmp}NewAdvSplash.dll'),'show','1600','800','500','-2',SplashFile,'','','','','');
// 以下是安装向导初始化函数的其它代码
// 请自己加上
end;
// 以下是其它 CODE 段代码
// 请自己加上
顶楼所介绍的脚本中播放音乐使用的是一个叫 BASSMOD.DLL 插件,该插件仅用于播放 MOD 格式的音乐文件(XM, IT, S3M, MOD, MTM, UMX)。该插件还有一个姊妹插件叫 BASS.DLL,它的功能更多更强。因为有人希望本人能够提供一个类似于顶楼但是能够播放 MP3 音乐文件的脚本,所以自己抽时间把 BASS.DLL 这方面的功能研究了一下,写出了下面的示例脚本。
该脚本与顶楼的脚本很相似,只是把插件 BASSMOD.DLL 换成了 BASS.DLL,把背景音乐 mymusic.mod 换成了 mymusic.mp3。BASS.DLL 文件可以从下面下载,mymusic.mp3 请自己准备(我这里找不到个头小的 mp3 文件),其它文件请从顶楼下载。WAV 格式的音乐文件也是支持的。
; INNO SETUP 脚本文件
; 该示例脚本创建带闪屏和背景音乐的安装程序
AppName=我的程序
AppVerName=我的程序 1.5 版本
DefaultDirName={pf}\我的程序
DefaultGroupName=我的程序
; 打包实现闪屏和背景音乐所必需的插件文件
Source: "Z:\NSISADDIN\callnsis.dll"; DestDir: "{tmp}"; Flags: dontcopy
Source: "Z:\NSISADDIN\NewAdvSplash.dll"; DestDir: "{tmp}"; Flags: dontcopy
Source: "Z:\NSISADDIN\Bass.dll"; DestDir: "{tmp}"; Flags: dontcopy
; 打包闪屏和背景音乐素材文件:闪屏图像文件 bmp、gif 或者 jpg 格式, 音乐文件 MP3、WAV 格式
Source: "Z:\NSISADDIN\splash.gif"; DestDir: "{tmp}"; Flags: dontcopy
Source: "Z:\NSISADDIN\mymusic.mp3"; DestDir: "{tmp}"; Flags: dontcopy
; 以下打包软件本身的文件
; 请自己加上
; 以下是安装脚本的其它段代码
; 请自己加上
Type
HSAMPLE = DWORD;
HCHANNEL = DWORD;
var
MusicSwitchLabel0, MusicSwitchLabel1, MusicSwitchLabel2: TNewStaticText;
sample: HSAMPLE;
channel: HCHANNEL;
// 以下是所调用的插件函数
function BASS_Init(device: Integer; freq, flags: DWORD; win: HWND; clsid: string): Boolean;
external 'BASS_Init@files:BASS.dll stdcall delayload';
procedure BASS_Free();
external 'BASS_Free@files:BASS.dll stdcall delayload';
function BASS_SampleLoad(mem: BOOL; f: PChar; offset, length, max, flags: DWORD): HSAMPLE;
external 'BASS_SampleLoad@files:BASS.dll stdcall delayload';
function BASS_ChannelPlay(handle: DWORD; restart: BOOL): BOOL;
external 'BASS_ChannelPlay@files:BASS.dll stdcall delayload';
function BASS_ChannelPause(handle: DWORD): BOOL;
external 'BASS_ChannelPause@files:BASS.dll stdcall delayload';
function BASS_SampleGetChannel(handle: HSAMPLE; onlynew: BOOL): HCHANNEL;
external 'BASS_SampleGetChannel@files:BASS.dll stdcall delayload';
procedure callplug(parentwnd: Integer; pluginname,funcname,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10: PChar);
external 'callplug@files:callnsis.dll stdcall delayload';
// 以下是点击“关于”按钮后的响应函数
procedure AboutButtonOnClick(Sender: TObject);
begin
MsgBox('这是你的信息。'#13#10'这是你的信息的第二行。', mbInformation, MB_OK);
end;
// 以下是点击“打开音乐”按钮后的响应函数
procedure MusicSwitchLabel1OnClick(Sender: TObject);
begin
BASS_ChannelPlay(channel, false);
MusicSwitchLabel1.Font.Color := clGray;
MusicSwitchLabel2.Font.Color := clBlue;
end;
// 以下是点击“关闭音乐”按钮后的响应函数
procedure MusicSwitchLabel2OnClick(Sender: TObject);
begin
BASS_ChannelPause(channel);
MusicSwitchLabel2.Font.Color := clGray;
MusicSwitchLabel1.Font.Color := clBlue;
end;
// 安装向导初始化函数
procedure InitializeWizard();
var
AboutButton: TButton;
BGMusicFile, SplashFile: string;
begin
// 创建“关于”按钮
AboutButton := TButton.Create(WizardForm);
AboutButton.Left := WizardForm.ClientWidth - WizardForm.CancelButton.Left - WizardForm.CancelButton.Width;
AboutButton.Top := WizardForm.CancelButton.Top;
AboutButton.Width := WizardForm.CancelButton.Width;
AboutButton.Height := WizardForm.CancelButton.Height;
AboutButton.Caption := '关于(&A)...';
AboutButton.OnClick := @AboutButtonOnClick;
AboutButton.Parent := WizardForm;
// 创建文字标签“音乐:”
MusicSwitchLabel0 := TNewStaticText.Create(WizardForm);
MusicSwitchLabel0.Left := AboutButton.Left + ScaleX(90);
MusicSwitchLabel0.Top := WizardForm.CancelButton.Top + ScaleY(3);
MusicSwitchLabel0.Width := ScaleX(30);
MusicSwitchLabel0.Height := ScaleY(12);
MusicSwitchLabel0.Font.Color := clRed;
MusicSwitchLabel0.Caption := '音乐:';
MusicSwitchLabel0.Parent := WizardForm;
// 创建文字标签作为“打开音乐”按钮(采用 Webdings 字体中的播放符号)
MusicSwitchLabel1 := TNewStaticText.Create(WizardForm);
MusicSwitchLabel1.Left := MusicSwitchLabel0.Left + ScaleX(33);
MusicSwitchLabel1.Top := MusicSwitchLabel0.Top - ScaleY(3);
MusicSwitchLabel1.Width := ScaleX(20);
MusicSwitchLabel1.Height := ScaleY(12);
MusicSwitchLabel1.Font.Color := clGray;
MusicSwitchLabel1.Font.Name := 'webdings';
MusicSwitchLabel1.Font.Size := -15;
MusicSwitchLabel1.Cursor := crCross;
MusicSwitchLabel1.Caption := #52
MusicSwitchLabel1.ShowHint:= true;
MusicSwitchLabel1.Hint:= '打开音乐';
MusicSwitchLabel1.OnClick := @MusicSwitchLabel1OnClick;
MusicSwitchLabel1.Parent := WizardForm;
// 创建文字标签作为“关闭音乐”按钮(采用 Webdings 字体中的暂停符号)
MusicSwitchLabel2 := TNewStaticText.Create(WizardForm);
MusicSwitchLabel2.Left := MusicSwitchLabel1.Left + ScaleX(20);
MusicSwitchLabel2.Top := MusicSwitchLabel0.Top - ScaleY(3);
MusicSwitchLabel2.Width := ScaleX(20);
MusicSwitchLabel2.Height := ScaleY(12);
MusicSwitchLabel2.Font.Color := clBlue;
MusicSwitchLabel2.Font.Name := 'webdings';
MusicSwitchLabel2.Font.Size := -15;
MusicSwitchLabel2.Cursor := crCross;
MusicSwitchLabel2.Caption := #59
MusicSwitchLabel2.ShowHint:= true;
MusicSwitchLabel2.Hint:= '关闭音乐';
MusicSwitchLabel2.OnClick := @MusicSwitchLabel2OnClick;
MusicSwitchLabel2.Parent := WizardForm;
// 释放临时文件
ExtractTemporaryFile('BASS.dll');
ExtractTemporaryFile('CallNSIS.DLL');
ExtractTemporaryFile('NewAdvSplash.DLL');
ExtractTemporaryFile('mymusic.mp3');
ExtractTemporaryFile('splash.gif');
BGMusicFile := ExpandConstant('{tmp}\mymusic.mp3');
SplashFile := ExpandConstant('{tmp}\splash.gif');
// 播放背景音乐
if not BASS_Init(-1,44100,0,0,'') then
BASS_Free;
sample := BASS_SampleLoad(false, PChar(BGMusicFile), 0, 0, 1, 4);
if sample<>0 then
begin
channel:= BASS_SampleGetChannel(sample, false);
BASS_ChannelPlay(channel, true);
end;
// 闪屏:显示时间 1600、淡入 800、淡出 500、透明颜色 -2 (表示 gif 图像本身透明)
callplug(0,ExpandConstant('{tmp}\NewAdvSplash.dll'),'show','1600','800','500','-2',SplashFile,'','','','','');
// 以下是安装向导初始化函数的其它代码
// 请自己加上
end;
// 以下是其它 CODE 段代码
// 请自己加上 纯inno脚本实现的闪屏,调用Win32 API实现,无需额外DLL,可以作为存为iss文件include来使用。
不过有一定局限性,只能使用bmp文件。
//调用方法:
//ShowSplash(bmp文件名, 宽,高, 淡入/淡出毫秒时间, 图片静止毫秒时间);
function SetLayeredWindowAttributes(hWnd: HWND; ColorRef: TColor; bAlpha:
byte; dwFlags: LongInt): boolean;
external 'SetLayeredWindowAttributes@user32 stdcall';
function SetWindowLong(hWnd : HWND; nIndex : integer; dwNewLong : Longint):
Longint;
external 'SetWindowLongA@user32 stdcall';
function GetWindowLong(hWnd : HWND; nIndex : integer): LongInt;
external 'GetWindowLongA@user32 stdcall';
const
WS_EX_LAYERED = $80000;
GWL_EXSTYLE = -20;
LWA_COLORKEY = 1;
LWA_ALPHA = 2;
FadeStep = 10;
procedure SetTransparentForm(AHandle : THandle; AValue : byte);
begin
SetWindowLong(AHandle, GWL_EXSTYLE, GetWindowLong(AHandle, GWL_EXSTYLE) or
WS_EX_LAYERED);
SetLayeredWindowAttributes(AHandle, 0, AValue, LWA_ALPHA);
end;
procedure ShowSplash(splashFileName: String; Width, Height, fadetime, stilltime: LongInt);
var
SplashForm: TForm;
SplashImage: TBitmapImage;
i, SleepSetp: LongInt;
begin
SplashForm := TForm.create(nil);
with SplashForm do
begin
Parent := nil;
BorderStyle := bsNone;
Position := poScreenCenter;
ClientWidth := Width;
ClientHeight := Height;
end;
SplashImage := TBitmapImage.Create(SplashForm);
with SplashImage do
begin
BitMap.LoadFromFile(SplashFileName);
Stretch := true;
Align := alClient;
Parent := SplashForm;
end;
with SplashForm do
begin
SetTransparentForm(SplashForm.handle, 0);
show;
Repaint;
SleepSetp := fadetime * FadeStep / 255;
for i := 1 to 255/FadeStep do
begin
SetTransparentForm(SplashForm.handle, i * FadeStep);
Sleep(SleepSetp);
end;
sleep(stilltime);
for i := 255/FadeStep downto 1 do
begin
SetTransparentForm(SplashForm.handle, i * FadeStep);
Sleep(SleepSetp);
end;
close;
release;
end;
end;
使用实例:
CODE
procedure InitializeWizard();
begin
ExtractTemporaryFile('MySplash.bmp');
ShowSplash(ExpandConstant('{tmp}\MySplash.bmp'), 240,200, 1000,3000);
end;
页:
[1]