Borland C++builder资源文件编辑
1 建立 现在从borland c++builder ->tools->Image Editor
Image Editor->File->New->Resource
在菜单中会出现resource 从new中选择资源分类有 bitmap icon cursor
若选择了bitmap 会出现选择位图的颜色和大小如果是从外部位图的话就要知道它的大小 其下会出现bitmap1 它就是位图文件名 选中他单击右键 edit 就进入绘图状态可以剪贴板中把外部位图考进来 然后就是保存了
2在c++builder 中Project->Add to Project… 装入资源文件
3使用 a. Graphics::TBitmap *Bitmap; //低颜色
Bitmap=new Graphics::Tbitmap();
Bitmap->Handle=LoadBitmap(int(hInstance),”Bitmap1”)
//256种颜色
b. LoadFromResourceName(int Instance,const AnsiString ResName);
LoadFromResourceID (int Instance,int ResID);
列如:
1 Graphics::TBitmap *Bitmap;
Bitmap=new Graphics::Tbitmap();
Bitmap->LoadFromResourceName(int (Hinstance),”picture1”);
2 Image1->Picture->Bitmap->LoadFromResourceName(int(HInstance),"Bitmap1");
注意 大 小 写 int(hInstance) int(HInstance)
手工操作
选用文本文件输入内容
Bitmap1 BITMAP “ C:\windows\bitmap1.bmp”
用brcc32.exe编译成资源文件 他在bin目录下 brcc32 –32 testwave.rc =>testwave.res
使用时在单元文件cpp中 # pragma resource “D:\\cbuilder\\picture.RES”
TForm1 *Form1;
注意
test.rc是一个纯文本文件,可用写字板建立,
但存盘时,文件名上要加上双引号即成 "test.rc",
否则会变成 wave.rc.txt
这种办法可把声音文件加到你的.exe中:
1.建立纯文本资源文件如wave.rc,内容如下:
ID_WAVE WAVE "C:\testwave.wav"
2.BCB中用Project->Add to Project 将test.rc
添加到你的工程中(即你的程序中);
3.在程序中:
代码:
#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)//res 可以 参数一是名称,参数二是类型名称 也就是RC中的 testwave WAVE “ c:\testwave.wav” 可以是WAV ,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);
}
如何把资源文件的文本读入到一个变量?
TResourceStream *rs=new TResourceStream((int)HInstance,"mydata","txt");
TStringList *ss=new TStringList;
ss->LoadFromStream(rs);
delete rs;
如何调用资源文件中res的jpeg、avi,wav,midi,mp3文件
Image中加入jpg可以用如下方法:
在文件头加入#include <jpeg.hpp>
在构造函数中加入
Image1->LoadFromResourceName(0, "JPEG");//你的资源名
Animate中加入avi可能也能用这种办法,不过没试过