• 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:UsersAdministratorDesktopExeRes.rc
    //brcc32.exe在DelphiXBin目录中 将其复制到 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:UsersAdministratorDesktopaaa.exe');
    end;




  • 相关阅读:
    直面焦虑烦恼 谈谈成长
    Makefile入门1
    递归
    极客时间的专栏
    作者介绍
    1.试除法判定质数 2.分解质因数 质数
    17.没有上司的舞会 树形DP
    17.二分图的最大匹配
    16.染色法判定二分图
    15.Kruskal算法求最小生成树
  • 原文地址:https://www.cnblogs.com/xe2011/p/3876377.html
Copyright © 2020-2023  润新知