Playing a wave sound from a resource file

来源:互联网 发布:linux samba 自启动 编辑:程序博客网 时间:2024/06/09 20:42
In article <01bbde3a$960b1a00$1500dece@dbrown.ee.net>, dbrown@ee.net says...I am attempting to have a wave file play when a button is clicked, in myDelphi application. Rather than install the wave file and use thePlaySound() API call, I'd like to put it into a resource file so that itplays with only the EXE present.

you need a resource compiler (i. E. Resource Workshop ) and add an user-defined-resource WAVE. You can play the resource-file in your program using


 

var FindHandle, ResHandle: THandle; ResPtr: Pointer; begin;  FindHandle:=FindResource(HInstance, '<Name of your Ressource>', 'WAVE');   if FindHandle<>0 then begin ResHandle:=LoadResource(HInstance, FindHandle);   if ResHandle<>0 then begin ResPtr:=LockResource(ResHandle); if ResPtr<>Nil then SndPlaySound(PChar(ResPtr), snd_ASync or snd_Memory);   UnlockResource(ResHandle); end;  FreeResource(FindHandle); 

原创粉丝点击