When we use sounds in our program, we have two options: to leave the wavs in the directory of our application or to put them inside our EXE, so that there are not loose files.
Here you have a description in the way easier of including your WAVs in the executable of your application:
First, we will build ourselves a resource file where we will put the files WAV
To make it it follows the steps that I here put you:
Making our .RC file
Open a text editor (Notepad, by example) and write:
SONIDO1 WAVE TADA.WAV
SONIDO2 WAVE OTRO.WAV
Save the file with RC extenxión, for example: Sonidos.RC
Compiling the .RC file
Now we should compile it, to create a file of resources (.RES), for that which, the best thing is that you put in the same directory as much the sounds as the file .RC that you have created.
To compile the file, we will use the Delphi compiler: the BRC32 (Borland resource Compiler) that you will have in the subdirectory /BIN inside the directory where you have installed the Delphi.
We will use:
BRC32.EXE -r -v Sonidos.RC
If everything has gone well, we will have generated the file Sonidos.RES
Including the .RES file in your application
Now, you should include in your application, the file .RES that you have created. You will make it including this line in your form, in the implementation part:
Playing these WAVs
It was time to make sound the sounds. Nothing else easy that to use the API function PlaySound.
For example, to make sound our first Wav, to which we have called him ' SONIDO1 ' in the resource file:
Waiting to the sound finishes (Syncron):
PlaySound(Pchar('SONIDO1'),hinstance,SND_RESOURCE Or SND_SYNC);
Without waiting to the sound finishes (ASyncron):
PlaySound(Pchar('SONIDO1'),hinstance,SND_RESOURCE Or SND_ASYNC);
Sent by: Antonio López (firstname.lastname@example.org)
Dont forget include MMSystem unit in your uses line...
Updated at 13/07/2001 MMSystem in the uses line