码迷,mamicode.com
首页 > 其他好文 > 详细

delphi 2010 资源文件使用

时间:2014-07-29 21:45:22      阅读:593      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   使用   os   文件   


Project 
            Recources...
bubuko.com,布布扣 bubuko.com,布布扣
bubuko.com,布布扣

bubuko.com,布布扣
//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;




delphi 2010 资源文件使用,布布扣,bubuko.com

delphi 2010 资源文件使用

标签:des   style   blog   http   color   使用   os   文件   

原文地址:http://www.cnblogs.com/xe2011/p/3876377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!