2010-08-26 100 views
0

我正在製作自己的安裝程序,它幾乎完成。唯一缺乏的是安裝完成時的聲音。這是一個Windows API調用,或者我將需要找到該音頻文件,並從源代碼播放?完成安裝的聲音

+0

我相信_you_做,但還是有太多的產品,發現不請,請,請尊重上/機器和用戶的聲音設置你正在運行你的安裝程序。在(安裝)應用程序中,我憎惡的不是發出不需要的聲音,也沒有辦法關閉它們。如果你走自定義聲音的路線:請尊重類似事件的系統聲音的設置。 – 2010-08-26 07:43:01

+5

我從來沒有聽說過一個Windows安裝程序在完成時播放聲音。從什麼時候發生? Mac安裝程序一直都在使用它,但Windows安裝程序不應該試圖僞裝成Mac安裝程序,反之亦然。另外,Rajeem,爲什麼當已經有那麼多的安裝工具已經解決了許多你可能還沒有想到的常見安裝任務時,你自己創建了安裝程序? – 2010-08-26 07:52:28

+0

實際上,它是一個插件安裝程序,它將用於配置INI和註冊表,這就是我選擇製作自己的安裝程序的原因。 有這麼多的安裝者可以播放聲音。嘗試在Delphi中執行這個聲音 - MessageBeep(MB_ICONINFORMATION)。我認爲這是最常用的聲音來通知用戶安裝已完成。 – rajeemcariazo 2010-08-26 08:26:00

回答

4

使用MessageBeep功能。

+0

)謝謝,我用過MessageBeep(MB_ICONINFORMATION); – rajeemcariazo 2010-08-26 07:45:18

0

您可以輕鬆播放系統默認的聲音通過:

System.Media.SystemSounds.Beep.Play(); 
System.Media.SystemSounds.Asterisk.Play(); 
System.Media.SystemSounds.Exclamation.Play(); 
System.Media.SystemSounds.Hand.Play(); 
System.Media.SystemSounds.Question.Play(); 
+1

看起來像一個.Net代碼,我實際上使用本機Delphi,對不起標籤Delphi – rajeemcariazo 2010-08-26 07:12:25

+0

但您確實標記了Win32和WinAPI,因此表明您正在使用本機Windows API,而不是.NET。 – 2010-08-26 07:23:21

+1

因此,正如Andreas所回答的那樣,使用MessageBeep(user32.dll)。如果您想要使用不同的聲音類型:星號= 0x40,蜂鳴聲= 0,感嘆號= 0X30,手= 0x10,問題= 0x20。 – Nissim 2010-08-26 07:39:02

1

這個函數的小集合將爲任何MCI支持的聲音文件加載,播放,停止和轉儲(可用內存)。 [* .WAV,* .MP3,* .WMA等..]

uses MMSystem; 

function LoadMediaFile(absoluteFile,clipName: String): Integer; 
var 
    pc2: PChar; 
    pc3: String; 
    begin 
     pc3 := '"'+absoluteFile+'"'; 
     pc2 := PChar('Open ' + pc3 + ' Alias '+ clipName); 
     Result := mciSendString(pc2, PChar(0), 0, 0); 
    end; 

function StartMediaFile(clipName: String) : Integer; 
var 
    pc2: PChar; 
    begin 
     pc2 := PChar('Play ' + clipName + ' From ' + '0'); 
     Result := mciSendString(pc2, PChar(0), 0, 0); 
    end; 

function StopMediaFile(clipName: String): Integer; 
var 
    pc2: PChar; 
    i: Integer; 
    begin 
     pc2 := PChar('Stop ' + clipName + ' wait'); 
     i := 0; 
     while (mciSendString(pc2, PChar(0), 0, 0)<>0) and (i < 250) do 
     begin 
      Result := mciSendString(pc2, PChar(0), 0, 0); i := i + 1; 
     end; 
    end; 

function DumpMediaFile(clipName: String): Integer; 
var 
    pc2,pc3: PChar; 
    i: Integer; 
    begin 
     pc2 := PChar('Stop ' + clipName + ' wait'); 
     pc3 := PChar('Close ' + clipName + ' Wait'); 
     i := 0; 
     while (mciSendString(pc2, PChar(0), 0, 0)<>0) and (i < 250) do 
     begin 
      mciSendString(pc2, PChar(0), 0, 0); i := i + 1; 
     end; 
     i := 0; 
     while (mciSendString(pc3, PChar(0), 0, 0)<>0) and (i < 250) do 
     begin 
      Result := mciSendString(pc3, PChar(0), 0, 0); i := i + 1; 
     end; 
    end; 

使用它們像這樣:

ResultInteger1 := LoadMediaFile('X:\Path\To\File.WAV', 'ClipName'); 
ResultInteger2 := StartMediaFile('ClipName'); 
Sleep(3000); 
ResultInteger3 := StopMediaFile('ClipName'); 
ResultInteger4 := DumpMediaFile('ClipName'); 

將扮演X 3秒:\路徑\要\ File.WAV文件。

您可以使用:

if ResultInteger2 <> 0 then ShowMessage('ClipName did not play.'); 
//or 
if ResultInteger2 = 0 then ShowMessage('ClipName did play.');