Sometimes, we write the program need to play music, generally we will use the following ways: 1. Place music files in a specific directory, such as Sound,wav,music for the program to read and play; 2. Use resources to store music. Some people may also use this method, but most people might have to release the music files from the resources before they read the playback. The way I'm going to present today is to load the music files directly into memory and then read them from memory. All right, here's the code:
Var
Hresinfo:thandle;
Ptrsound:pointer;
Begin
Hresinfo: = FindResource (hinstance, ' sound ', ' WAV ');
HRes: = LoadResource (hinstance, hresinfo);
If hres >
Begin
Ptrsound: = Lockresource (hres);
End
sndPlaySound (Ptrsound, Snd_async or snd_memory);
End
The core code is given, as long as we have to make a resource file, first, we first create a file with the extension RC
Where sound is the resource name, the WAV resource type, and the girl.wav is the music file.
Then we put the music file and the RC file in the same directory, compiled with BRCC32, the directory will generate a res extension file, the file will be placed in the Delphi project folder, in the unit's implementation {$R *.DFM} under the {$R Girl.res}, the final compilation can be.
Http://www.lsworks.net/article/1.html
Playing WAV from memory using sndPlaySound