如何在Inno设置中点击按钮声音?
我的意思是“Back”,“Next”和“Cancel”的不同。
我知道可能会有一些问题和答案,但我是这个网站的新手,我需要一些帮助。
提前致谢...
答案 0 :(得分:1)
您可以使用Inno Media Player播放声音。
请参阅问题Playing sound during an Inno Setup install。
要在按钮点击时触发声音,请使用以下代码:
[Files]
Source: "next.mp3"; Flags: dontcopy
Source: "back.mp3"; Flags: dontcopy
Source: "cancel.mp3"; Flags: dontcopy
Source: "MediaPlayer.dll"; Flags: dontcopy
[Code]
type
TDirectShowEventProc = procedure(EventCode, Param1, Param2: Integer);
function DSInitializeAudioFile(
FileName: string; CallbackProc: TDirectShowEventProc): Boolean;
external 'DSInitializeAudioFile@files:mediaplayer.dll stdcall';
function DSPlayMediaFile: Boolean;
external 'DSPlayMediaFile@files:mediaplayer.dll stdcall';
function DSStopMediaPlay: Boolean;
external 'DSStopMediaPlay@files:mediaplayer.dll stdcall';
function GetTickCount: DWORD;
external 'GetTickCount@kernel32.dll stdcall';
procedure DeinitializeSetup;
begin
DSStopMediaPlay;
end;
var
PageChanged: DWORD;
procedure CurPageChanged(CurPageID: Integer);
begin
PageChanged := GetTickCount;
end;
procedure DirectShowEvent(EventCode, Param1, Param2: Integer);
begin
{ dummy }
end;
procedure PlaySound(FileName: string);
begin
DSStopMediaPlay;
ExtractTemporaryFile(FileName);
if DSInitializeAudioFile(ExpandConstant('{tmp}\') + FileName, @DirectShowEvent) then
begin
DSPlayMediaFile;
end;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
{ NextButtonClick is called even for skipped pages (like the Welcome page) and }
{ during silent installs. To detect that, we check if at least half }
{ second elapsed since the page was shown }
if GetTickCount - PageChanged > 500 then
begin
PlaySound('next.mp3');
end;
Result := True;
end;
function BackButtonClick(CurPageID: Integer): Boolean;
begin
PlaySound('back.mp3');
Result := True;
end;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
PlaySound('cancel.mp3');
end;