http://www.latiumsoftware.com/en/delphi/00024.phpuses MMSystem;procedure TForm1.Button1Click(Sender: TObject); begin sndPlaySound('C:\Windows\Media\Tada.wav', SND_NODEFAULT Or SND_ASYNC Or SND_LOOP); end;procedure TForm1.Button2Click(Sender: TObject); begin sndPlaySound(nil, 0); // Stops the sound end;
HRESULT PlaySound ( BSTR bstrSound, OLE_HANDLE hModule, DWORD dwSound, DWORD dwId );bstrSound BSTR that specifies the sound file to play. hModule Handle of the executable file that contains the resource to load. dwSound Specifies the flag for playing the sound. The following values are defined: SND_APPLICATION SND_NODEFAULT SND_ALIAS SND_NOSTOP SND_ALIAS_ID SND_NOWAIT SND_ASYNC SND_PURGE SND_FILENAME SND_RESOURCE SND_LOOP SND_SYNC SND_MEMORY For more information about these flags, see the documentation for the Windows CE PlaySound function. dwId Specifies the book identifier. The parameter is ignored if 0. Return Values NOERROR Indicates success. E_INVALIDARG Indicates that the argument is invalid or incompatible. E_OUTOFMEMORY The system ran out of memory during processing.
begin
sndPlaySound('C:\Windows\Media\Tada.wav',
SND_NODEFAULT Or SND_ASYNC Or SND_LOOP);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
sndPlaySound(nil, 0); // Stops the sound
end;
BSTR bstrSound,
OLE_HANDLE hModule,
DWORD dwSound,
DWORD dwId );bstrSound
BSTR that specifies the sound file to play.
hModule
Handle of the executable file that contains the resource to load.
dwSound
Specifies the flag for playing the sound.
The following values are defined: SND_APPLICATION SND_NODEFAULT
SND_ALIAS SND_NOSTOP
SND_ALIAS_ID SND_NOWAIT
SND_ASYNC SND_PURGE
SND_FILENAME SND_RESOURCE
SND_LOOP SND_SYNC
SND_MEMORY For more information about these flags, see the documentation for the Windows CE PlaySound function. dwId
Specifies the book identifier. The parameter is ignored if 0.
Return Values NOERROR
Indicates success.
E_INVALIDARG
Indicates that the argument is invalid or incompatible.
E_OUTOFMEMORY
The system ran out of memory during processing.