【问题标题】:How to have a custom click sound on button click in Inno Setup (Back + Next + Cancel)?如何在 Inno 设置(返回 + 下一步 + 取消)中单击按钮时自定义单击声音?
【发布时间】:2016-09-18 05:13:01
【问题描述】:

如何在 Inno 设置中有按钮点击声音?

“Back”“Next”“Cancel” 的意思不同。

我知道可能会有一些问题和答案,但我是这个网站的新手,我需要一些帮助。

提前谢谢...

【问题讨论】:

    标签: audio inno-setup pascalscript


    【解决方案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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2019-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多