随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

//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.
posted on 2008-02-15 12:00  万一  阅读(...)  评论(...编辑  收藏