首页 > 代码库 > delphi 2010 资源文件使用
delphi 2010 资源文件使用
Project Recources...
//1提取出资源
procedure TForm1.Button1Click(Sender: TObject);
begin
with TResourceStream.Create(HInstance, ‘SnapShot_EXE‘, RT_RCDATA) do
begin
SavetoFile(‘SnapShot.exe‘);
Free;
end;
end;
//播放wav文件
//使用icon 文件
TResourceStream = class(TCustomMemoryStream) private HResInfo: THandle; HGlobal: THandle; procedure Initialize(Instance: THandle; Name, ResType: PChar; FromID: Boolean); public constructor Create(Instance: THandle; const ResName: string; ResType: PChar); constructor CreateFromID(Instance: THandle; ResID: Integer; ResType: PChar); destructor Destroy; override; function Write(const Buffer; Count: Longint): Longint; override; end;
const
{ Predefined Resource Types }
{$EXTERNALSYM RT_CURSOR}
RT_CURSOR = MakeIntResource(1); //光标文件
{$EXTERNALSYM RT_BITMAP}
RT_BITMAP = MakeIntResource(2);//位图
{$EXTERNALSYM RT_ICON}
RT_ICON = MakeIntResource(3);//图标
{$EXTERNALSYM RT_MENU}
RT_MENU = MakeIntResource(4);
{$EXTERNALSYM RT_DIALOG}
RT_DIALOG = MakeIntResource(5);
{$EXTERNALSYM RT_STRING}
RT_STRING = MakeIntResource(6);
{$EXTERNALSYM RT_FONTDIR}
RT_FONTDIR = MakeIntResource(7);
{$EXTERNALSYM RT_FONT}
RT_FONT = MakeIntResource(8);
{$EXTERNALSYM RT_ACCELERATOR}
RT_ACCELERATOR = MakeIntResource(9);
{$EXTERNALSYM RT_RCDATA}
RT_RCDATA = Types.RT_RCDATA; //MakeIntResource(10);
{$EXTERNALSYM RT_MESSAGETABLE}
RT_MESSAGETABLE = MakeIntResource(11);
DIFFERENCE = 11;
{$EXTERNALSYM DIFFERENCE}
RT_GROUP_CURSOR = MakeIntResource(DWORD(RT_CURSOR) + DIFFERENCE);
{$EXTERNALSYM RT_GROUP_CURSOR}
RT_GROUP_ICON = MakeIntResource(DWORD(RT_ICON) + DIFFERENCE);
{$EXTERNALSYM RT_GROUP_ICON}
RT_VERSION = MakeIntResource(16);
{$EXTERNALSYM RT_VERSION}
RT_DLGINCLUDE = MakeIntResource(17);
{$EXTERNALSYM RT_DLGINCLUDE}
RT_PLUGPLAY = MakeIntResource(19);
{$EXTERNALSYM RT_PLUGPLAY}
RT_VXD = MakeIntResource(20);
{$EXTERNALSYM RT_VXD}
RT_ANICURSOR = MakeIntResource(21);
{$EXTERNALSYM RT_ANICURSOR}
RT_ANIICON = MakeIntResource(22);
{$EXTERNALSYM RT_ANIICON}
RT_HTML = MakeIntResource(23);
{$EXTERNALSYM RT_HTML}
RT_MANIFEST = MakeIntResource(24);
{取出现Wav资源}
with TResourceStream.Create(HInstance, ‘warning‘, RT_RCDATA) do
begin
SaveToFile(‘warning.wav‘);
Free;
end;
//把EXE文件打包到资源文件中
一.编写rc脚本文本
新建一个记事本,输入 ExeFile1 ExeFile "myExeFile.exe" 保存文件为 ExeRes.rc
二.将rc文件编译成res资源文件
在dos中输入
brcc32 C:\Users\Administrator\Desktop\ExeRes.rc
//brcc32.exe在DelphiX\Bin目录中 将其复制到 C:\Windows目录下面
三.在Delphi单元中加入资源文件
新建一个项目,把ExeRes.RES文件复制到 项目目录下,
在 implementation 的{$R *.dfm}的下面输入:
{$R ExeRes.RES}
四.把资源文件中exe文件提取出来uses classes;
procedure ExtractRes( ResType, ResName, ResNewName : String );
var
Res : TResourceStream;
begin
Res := TResourceStream.Create(Hinstance, Resname, Pchar(ResType));
Res.SavetoFile(ResNewName);
Res.Free;
end;
//把资源文件中exe文件提取出来
procedure TForm1.Button1Click(Sender: TObject);
begin
ExtractRes(‘exefile‘,‘ExeFile1‘,‘C:\Users\Administrator\Desktop\aaa.exe‘);
end;
来自为知笔记(Wiz)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。