The popular saying is: "16-bit delphi 1.0 and 32-bit delphi2.0 and 3.0 all provide resources
Compilation tool. The resource compiler of Delphi 1.0 is BRCC. EXE and the resource compiler of Delphi 2.0.
Brcc32.exe is used to compile 32-bit resources. All resource compilers only provide the command line version,
Windows version not provided. To create a resource, follow these steps:
1) Compile the. RC file
The. RC file is the source file of the resource, and the compiler will compile the file to generate the. Res
Resource file
First, create a plain text file named
Sound. RC, in the file
There is a row with the following content:
Sound1 WAV sound. wav
Sound. wav is a normal sound file in windows.
2) compile it
After playing the BRCC sound. RC hard drive at the DOS prompt, edit it.
Translated
3) Production Program
This is also the most complex and flexible step. First, start Windows and then start Delphi,
And
To the subdirectory in our project. Find this in unit1.pas
One row
{$ R *. DFM}
Declare our resource file at the end
{$ R sound. Res}
Then, declare two global variables in form1.
Ptrsound: pchar;
Hres: thandle; {handle to the loaded Resource
If 0 indicates nothing playing}
Write down the following in the create event of form1: Code
Procedure tform1.formcreate (Sender: tobject );
VaR hresinfo: thandle;
Begin
Hresinfo: = findresource (hinstance, 'sound1', 'powerwave ');
Hres: = loadresource (hinstance, hresinfo );
If hres> 32 then {its a good load}
Begin {lock the resource}
Ptrsound: = lockresource (hres );
End;
End;
Put the button button1 in form1 and write the following code:
Procedure tform1.button1click (Sender: tobject );
Begin
Sndplaysound (ptrsound, snd_async or snd_memory );
End;
You can run it now ."
Is it true?
In fact, the file name of the resource file cannot be the same as that of the wave file.
Below I can write a run Source code (Of course, your resource file cannot be wrong ):
1) Compile the. RC file
The. RC file is the source file of the resource, and the compiler will compile the file to generate the. Res resource file. First, create a plain text file in our project subdirectory named
Pad. RC: Write a line in the file with the following content: // note! The resource file name cannot be the same as the wave file name!
Sound1 WAV sound. wav
Sound. wav is a normal sound file in windows.
2) compile it
After playing brcc32 pad. RC at the DOS prompt, the compilation is complete. // It is now brcc32. Article Why is there BRCC ??
3) Program Creation
Start Delphi in windows, create a project, and save the files to the subdirectories in our project. In unit1.pas, find
{$ R *. DFM}
Declare our resource file at the end
{$ R pad. Res}
Then, declare two global variables in form1.
Ptrsound: pchar;
Hres: thandle; {handle to the loaded Resource
If 0 indicates nothing playing}
Then write the following code in the create event of form1:
Procedure tform1.formcreate (Sender: tobject );
VaR hresinfo: thandle;
Begin
Hresinfo: = findresource (hinstance, 'sound1', 'powerwave ');
Hres: = loadresource (hinstance, hresinfo );
If hres> 32 then {its a good load}
Begin {lock the resource}
Ptrsound: = lockresource (hres );
End;
End;
Put the button button1 in form1 and write the following code:
Procedure tform1.button1click (Sender: tobject );
Begin
Sndplaysound (ptrsound, snd_async or snd_memory );
End;
Click compile, run, and then press button1 to hear the contents of the wave file from the speaker.