Author: Tomas Rutkauskas
I am attempting to have a wave file played when a button is clicked. Rather than
install the wave file and use the PlaySound() API call, I'd like to put it into a
resource file so that it plays with only the EXE present.
Answer:
1 { ... }2 var3 FindHandle, ResHandle: THandle;
4 ResPtr: Pointer;
5 begin6 FindHandle := FindResource(HInstance, 'Name of your resource', 'WAVE');
7 if FindHandle <> 0 then8 begin9 ResHandle := LoadResource(HInstance, FindHandle);
10 if ResHandle <> 0 then11 begin12 ResPtr := LockResource(ResHandle);
13 if ResPtr <> nilthen14 SndPlaySound(PChar(ResPtr), snd_ASync or snd_Memory);
15 UnlockResource(ResHandle);
16 end;
17 FreeResource(FindHandle);
18 end;
19 end;