How to add a *.wav file to a resource file in Delphi

Source: Internet
Author: User

"Popular" is said to be: "16-bit Delphi 1.0 and 32-bit Delphi2.0, 3.0 have provided the resources

Compiler tool, where Delphi 1.0 resource compiler is called Brcc.exe,delphi 2.0 Resource Compiler

Called BRCC32.EXE to compile a 32-bit resource, all resource compilers provide only command-line versions.

The Windows version is not available. Creating a resource typically takes the following steps:

1) write. RC file

.. The RC file is the source file of the resource, and the compiler compiles the file to generate it. Res's

Resource file

First, create a plain text file in our project subdirectory named

Sound.rc, in the file

There is a row with the content:

SOUND1 WAV Sound. Wav

Where sound.wav is a common sound file under Windows

2) Compile It

At the DOS prompt, hit BRCC sound. RC hard drive after a while,

Finished translation

3) Production process


This is also the most complex, most flexible step, first start Windows, and then start Delphi,

and the project

Save the file in a subdirectory in our project. Looking for such a unit1.pas in the

Line


{$R *. DFM}


We're going to declare our resource files in the back.


{$R sound. RES}

Then, declare two global variables in Form1


Ptrsound:pchar;

Hres:thandle; {Handle to the loaded resource

If 0 indicates nothing playing}


In the Form1 create event, write the following code


Procedure Tform1.formcreate (Sender:tobject);

var Hresinfo:thandle;

Begin

Hresinfo: = FindResource (hinstance, ' SOUND1 ', ' WAVE ');

HRes: = LoadResource (hinstance, hresinfo);

If hres > Then {its a good load}

Begin {Lock the resource}

Ptrsound:=lockresource (hres);

End

End

Then put a button in the Form1 Button1, write the following code:


Procedure Tform1.button1click (Sender:tobject);

Begin

sndPlaySound (Ptrsound,snd_async or snd_memory);

End

This is the time to run. ”

Is it true?

In fact, the file name of the resource files can not be the same as the wave file, otherwise, hehe, the speaker will be beep, do not believe you try.

The following author writes the steps to run the source code (of course your resource file cannot be wrong):


1) write. RC file


.. The RC file is the source file of the resource, and the compiler compiles the file to generate it. Res resource file first creates a plain text file in our project subdirectory named

Pad.rc, write a line in the file, the content is://Note! The resource file name cannot be the same as the wave file name!

SOUND1 WAV Sound. Wav

Where sound.wav is a common sound file under Windows

2) Compile It

Play BRCC32 PAD under the DOS prompt. RC after a while, it was compiled//now is BRCC32, I do not know how there are some articles BRCC??

3) Production process

Start Delphi under Windows, create a new project, and save the files in a subdirectory in our project. Found in Unit1.pas


{$R *. DFM}


We're going to declare our resource files in the back.


{$R PAD. RES}


Then, declare two global variables in Form1

Ptrsound:pchar;

Hres:thandle; {Handle to the loaded resource

If 0 indicates nothing playing}

In the Form1 create event, write the following code


Procedure Tform1.formcreate (Sender:tobject);

var Hresinfo:thandle;

Begin

Hresinfo: = FindResource (hinstance, ' SOUND1 ', ' WAVE ');

HRes: = LoadResource (hinstance, hresinfo);

If hres > Then {its a good load}

Begin {Lock the resource}

Ptrsound:=lockresource (hres);

End

End


Then put a button in the Form1 Button1, write the following code:

Procedure Tform1.button1click (Sender:tobject);

Begin

sndPlaySound (Ptrsound,snd_async or snd_memory);

End


Click Compile, run, then press BUTTON1, you can hear the wave file content in the speaker.

Http://www.cnblogs.com/dashan9zj/archive/2009/01/16/1377181.html

How to add a *.wav file to a resource file in Delphi

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.