Borland C ++ builder resource file editing

Source: Internet
Author: User
Borland C ++ builder resource file editing
1 create now from Borland C ++ builder-> Tools-> image editor
Image editor-> file-> New-> Resource
In the menu, bitmap icon cursor is selected for resource from new.
If bitmap is selected, the color and size of the selected bitmap will appear. If it is from an external bitmap, it will be known its size. bitmap1 will appear under it. It is the bitmap file name. Right-click it and click Edit to enter the drawing state. you can test the external bitmap in the clipboard and save it.
2. In C ++ builder, choose Project> Add to project... Load resource files
3 Use A. Graphics: tbitmap * bitmap; // low color
Bitmap = new graphics: tbitmap ();
Bitmap-> handle = loadbitmap (INT (hinstance), "bitmap1 ")
// 256 colors
B. loadfromresourcename (INT instance, const ansistring resname );
Loadfromresourceid (INT instance, int resid );
Example:
1 graphics: tbitmap * bitmap;
Bitmap = new graphics: tbitmap ();
Bitmap-> loadfromresourcename (INT (hinstance), "picture1 ");
2 image1-> picture-> Bitmap-> loadfromresourcename (INT (hinstance),/"bitmap1 /");
Note that the INT (hinstance) int (hinstance)
Manual Operation
Select text file input content
Bitmap1 bitmap "C: // windows // bitmap1.bmp"
Use brcc32.exe to compile the source file. In the bin directory, brcc32-32 testwave. Rc => testwave. Res
# Pragma resource "D: // cbuilder // picture. Res" in the unit file CPP for use"
Tform1 * form1;
Note:
Test. RC is a plain text file that can be created on a wordpad,
However, when saving the disk, the file name must be enclosed in double quotation marks (/"test. RC /",
Otherwise it will become wave.rc.txt
This method can be used to add the audio and audio files to your .exe:
1. Create a text-only resource file, such as wave. Rc. The content is as follows:
Id_wave wave/"C: // testwave.wav /"
2. Use Project-> Add to project in BCB to convert test. RC
Add to your project (in your program );
3. In the program:
# Include/"mmsystem. h /"
Playsound (/"id_wave/", hinstance, snd_resource );
Playsound () & rc
//---------------------------------------------------------------------------
Void _ fastcall tform1: fromfileclick (tobject * sender)
{
Playsound (/"mail.wav/", null, snd_filename );
}
//---------------------------------------------------------------------------
Void _ fastcall tform1: fromfilememoryclick (tobject * sender)
{
Tfilestream * wavefile = new tfilestream (/"mail.wav/", fmopenread );
Byte * wavemem = new byte [wavefile-> size + 1];
Wavefile-> Read (wavemem, wavefile-> size );
Playsound (wavemem, null, snd_memory );
Delete [] wavemem;
Delete wavefile;
}
//---------------------------------------------------------------------------
Void _ fastcall tform1: fromresourceclick (tobject * sender)
{
Playsound (/"mail/", hinstance, snd_resource );
}
//---------------------------------------------------------------------------
Void _ fastcall tform1: fromresourcememoryclick (tobject * sender) // The parameter can be a name or a type name, that is, testwave wave "C: // testwave.wav "can be any WAV or wav_data
{
Handle reshandle;
Byte * wavdata;
Reshandle = findresource (hinstance,/"mail/",/"wave /");
Reshandle = loadresource (hinstance, reshandle );
Wavdata = (unsigned char *) lockresource (reshandle );
Playsound (wavdata, null, snd_memory );
Freeresource (reshandle );
}
How can I read the text of a resource file into a variable?
Tresourcestream * rs = new tresourcestream (INT) hinstance,/"mydata/",/"TXT /");
Tstringlist * Ss = new tstringlist;
SS-> loadfromstream (RS );
Delete RS;
How to call res JPEG, Avi, WAV, Midi, and MP3 files in resource files
You can use the following method to add JPG to an image:
Add # include <jpeg. HPP> to the file header.
Add to Constructor
Image1-> loadfromresourcename (0,/"Jpeg/"); // your Resource Name
This method can also be used if Avi is added to animate, but it has never been tried.
Use of various resources in BC ++ builder 3.0
Li Jin, Science and Technology Department, China Construction Bank, Yantai South Street
---- Various types of resource sources are often used in the programming process. For example, I want to change the sequence of my own graph, so that I can use some lively light labels to increase the interesting taste, play a sound and animation file, or use other people's programming order to implement a certain function. We hope to put these resources directly to the EXE file to form a single executable file, this is stored in a question about how to access and use these resources during operation.
---- During the compilation and translation period, a document should be used to define the document based on the resource source ending with. RC.
---- 1: RC file
---- RC is a document. Its format is simple and its definition is as follows:
---- Path of the resource source mark to the resource Source Type
---- The RC file below defines an Audio Resource source, two optical resource sources, three graphic resource sources and one EXE file resource source.
Src1.rc:
S1 WAV wav1.wav
C1 cursor cursor1.cur
C2 cursor cursor2.cur
I1 icon icone1.ico
I2 icon icone2.ico
I3 icon icone3.ico
Unzip exefile pkunzip.exe
---- You can add the written RC file to your project. You can also compile it as a binary source file (. Res file) for direct use by hand ). In bcb3.0, you can use the command line brcc32 src1.rc src1.res.
---- II. Use of Resources
---- The following describes the usage methods of various types of resource sources based on the simplicity and complexity of usage. It should be noted that the usage method described in the following section is also similar to the compiling and translation environment (BC, Vc, etc.
---- 1: Create a new project
---- Start bcb3.0 and choose File> New> application to create a new project.
---- Add the written src1.rc file in project-> Add to project. However, the audio, optical mark, and graphic mark files should be stored.
---- At this time, we have an empty form ).
---- 2: The resources that can be accessed directly by using Windows APIs include:
Loadicon ()
Loadcursor ()
Acceleration table loadaccelerators ()
Bitmap ()
Food order loadmenu ()
String loadstring ()
---- The first five API functions use the same method, with two parameters.
---- The first parameter indicates the place where the resource source is stored. The second parameter is the identifier of the resource source in the RC file.
---- In addition to the two parameters, loadstring also has two parameters, indicating the location and size of the slow-forward area of the string.
---- A small sequence below shows the usage of the image label and the optical mark.
---- Place a button on the form and add the following code to its onclick event:
Void _ fastcall tform1: button1click (tobject * sender ){
// Change the cursor shape to your own:
Screen-> cursors [crdefault] = loadcursor (hinstance,/"C1 /");
// Change the icon to the custom one:
Icon = new ticon ();
Icon-> handle = loadicon (hinstance,/"I1 /");
Application-> icon = icon;
}
---- The hinstance indicates that the asset source is in the local delivery file. After editing and executing the code, click the button to change the optical and graphic labels to new ones.
---- 3: The resource source that can be used through Windows API
---- For audio, animation, and other files, you can use Windows API to play data. However, it is not similar to several types of resources on the top. You must follow the specific steps. As shown in the following figure, use findresource, loadresource, and lockresource to play a WAV audio file.
---- (However, a stand-alone audio file can be directly played during the operation. We will discuss the situation of compiling WAV Files into EXE files)
---- Place the second token on the form, and add the following code to The onclick event:
Void _ fastcall tform1: button2click (tobject * sender)
// Define the resource block
Char * wav_handle;
// Load the wav file
Hrsrc H = findresource (hinstance,/"S1/",/"WAV /");
Hglobal H1 = loadresource (hinstance, H );
Wav_handle = (char *) lockresource (H1 );
// Play the wav file. As wav files are loaded in the memory,
The sndplaysound function must use the snd_memory parameter.
Sndplaysound (wav_handle, snd_memory? Snd_sync );
}
---- After editing and executing the line, click the button to play a sound.
---- For text files such as animation, the style is similar to WAV Files. (BCB provides a tanimate control module, which can be used to play non-vocal AVI files)
---- 4: cannot directly connect to the resource used by Windows API
---- This type of resource cannot be directly accessed and executed by Windows API. However, we can use it as a method of change.
---- The following example shows how to use pkunzip.exe, and the path is as follows: when the program is run, pkunzip.exe is separated from the EXE file, put it in the current directory and run it with ShellExecute.
---- Place the third button on the form, and put two edits to input the pkunzip.exe parameter.
 

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.