//rc 文件:
sound1 WAVE "SoundFile1.wav"
sound2 WAVE "SoundFile2.wav"
//代碼:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses MMSystem; {下面用到的 sndPlaySound、PlaySound 都是在此單元聲明的}
procedure TForm1.Button1Click(Sender: TObject);
var
rs: TResourceStream;
begin
rs := TResourceStream.Create(HInstance, 'sound1', 'WAVE');
sndPlaySound(rs.Memory, SND_ASYNC or SND_MEMORY);
rs.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
rs: TResourceStream;
begin
rs := TResourceStream.Create(HInstance, 'sound2', 'WAVE');
PlaySound(rs.Memory, HInstance, SND_ASYNC or SND_MEMORY);
rs.Free;
end;
end.