完成安装的声音

问题描述:

我正在制作自己的安装程序,它几乎完成。唯一缺乏的是安装完成时的声音。这是一个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

使用MessageBeep功能。

+0

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

您可以轻松播放系统默认的声音通过:

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

这个函数的小集合将为任何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.');