How to add *. wav files to resource files in Delphi

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.