Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.09.25;
Скачать: CL | DM;

Вниз

EnumResourceTypes, EnumResTypeProc ...   Найти похожие ветки 

 
vic_774N ©   (2003-07-24 00:02) [0]

Здравствуйте !
Поиск в нете к сожалению пока ничего не дал, так что если кто может подсказать (пример использования этих функций, Resource Function) сообщите сюда или бросьте в ящик пожалуста !


 
vic_774N ©   (2003-07-24 08:51) [1]

вот то что я пытаюсь заставить работать:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellApi;

type
TResEnum = record
ResType: array [0..99] of string[20];
ResName: array [0..99] of string;
ResHandle: array [0..99] of THandle;
ResCount: Integer;
end;


type
TForm1 = class(TForm)
Label1: TLabel;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
procedure Label1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
s: TResEnum;

implementation

{$R *.DFM}



procedure TForm1.Label1Click(Sender: TObject);
function EnumNames(hModule: THandle; szType: PChar;
szName: PChar; lParam: LongInt): Bool; stdcall;
begin
s.ResName[s.ResCount] := szName;
Boolean(Pointer(lParam)^) := True;
Result := True;
end;

function EnumTypes(hModule: THandle; szType: PChar;
lParam: LongInt): Bool; stdcall;
begin
Result := False;

if szType = RT_CURSOR then
begin
s.ResType[s.ResCount] :="RT_CURSOR";
Inc(s.ResCount);
end;

if szType = RT_BITMAP then
begin
s.ResType[s.ResCount]:="RT_BITMAP";
Inc(s.ResCount);
end;

if szType = RT_ICON then
begin
s.ResType[s.ResCount]:="RT_ICON";
Inc(s.ResCount);
EnumResourceNames(hModule, szType, @EnumNames, lParam);
end;

if szType = RT_MENU then
begin
s.ResType[s.ResCount]:="RT_MENU";
Inc(s.ResCount);
end;

if szType = RT_DIALOG then
begin
s.ResType[s.ResCount]:="RT_DIALOG";
Inc(s.ResCount);
end;

if szType = RT_STRING then
begin
s.ResType[s.ResCount]:="RT_STRING";
Inc(s.ResCount);
end;

if szType = RT_FONTDIR then
begin
s.ResType[s.ResCount]:="RT_FONTDIR";
Inc(s.ResCount);
end;

if szType = RT_FONT then
begin
s.ResType[s.ResCount]:="RT_FONT";
Inc(s.ResCount);
end;

if szType = RT_ACCELERATOR then
begin
s.ResType[s.ResCount]:="RT_ACCELERATOR";
Inc(s.ResCount);
end;

if szType = RT_MESSAGETABLE then
begin
s.ResType[s.ResCount]:="RT_MESSAGETABLE";
Inc(s.ResCount);
end;

if szType = RT_RCDATA then
begin
s.ResType[s.ResCount]:="RT_RCDATA";
Inc(s.ResCount);
Result := False;
end
else
Result := True;

end;


var
HLib: THandle;
h: THandle;
hres: THandle;
pnr: Pointer;
icon: TIcon;
i: Integer;
begin
s.ResCount:=0;
Memo1.Clear;
Application.ProcessMessages;

if OpenDialog1.Execute then
begin
HLib := 0;
HLib := LoadLibraryEx(PChar(OpenDialog1.FileName), 0, LOAD_LIBRARY_AS_DATAFILE);
if HLib <> 0 then
begin
Label1.Caption:=IntToStr(HLib);
//h := FindResource(HLib, nil, RT_ICON);
if not EnumResourceTypes(HLib, @EnumTypes , 0) then
MessageDlg("Not find resources", mtWarning, [mbOK], 0);

if not EnumResourceNames(HLib, RT_ICON, @EnumNames, 0) then
MessageDlg("Not find names", mtWarning, [mbOK], 0);



for i:=0 to s.ResCount-1 do
Memo1.Lines.Append(s.ResType[i] + " " + s.ResName[i]);


h := FindResource(HLib, PChar(s.ResName[0]) , "RT_ICON"); // h всегда равно 0 тк s.ResName = "" !!!!
if h = 0 then MessageDlg(IntToStr(GetLastError), mtError, [mbOK], 0);

if h <> 0 then
begin
hres := LoadResource(HLib, h);
icon := TIcon.Create;
icon.Handle := hres;
icon.SaveToFile("new.ico");
FreeResource(hres);
icon.Free;
end;
//pnr:=EnumResTypeProc(ResH);

( HLib)
вот то что я пытаюсь заставить работать:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellApi;

type
TResEnum = record
ResType: array [0..99] of string[20];
ResName: array [0..99] of string;
ResHandle: array [0..99] of THandle;
ResCount: Integer;
end;


type
TForm1 = class(TForm)
Label1: TLabel;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
procedure Label1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
s: TResEnum;

implementation

{$R *.DFM}



procedure TForm1.Label1Click(Sender: TObject);
function EnumNames(hModule: THandle; szType: PChar;
szName: PChar; lParam: LongInt): Bool; stdcall;
begin
s.ResName[s.ResCount] := szName;
Boolean(Pointer(lParam)^) := True;
Result := True;
end;

function EnumTypes(hModule: THandle; szType: PChar;
lParam: LongInt): Bool; stdcall;
begin
Result := False;

if szType = RT_CURSOR then
begin
s.ResType[s.ResCount] :="RT_CURSOR";
Inc(s.ResCount);
end;

if szType = RT_BITMAP then
begin
s.ResType[s.ResCount]:="RT_BITMAP";
Inc(s.ResCount);
end;

if szType = RT_ICON then
begin
s.ResType[s.ResCount]:="RT_ICON";
Inc(s.ResCount);
EnumResourceNames(hModule, szType, @EnumNames, lParam);
end;

if szType = RT_MENU then
begin
s.ResType[s.ResCount]:="RT_MENU";
Inc(s.ResCount);
end;

if szType = RT_DIALOG then
begin
s.ResType[s.ResCount]:="RT_DIALOG";
Inc(s.ResCount);
end;

if szType = RT_STRING then
begin
s.ResType[s.ResCount]:="RT_STRING";
Inc(s.ResCount);
end;

if szType = RT_FONTDIR then
begin
s.ResType[s.ResCount]:="RT_FONTDIR";
Inc(s.ResCount);
end;

if szType = RT_FONT then
begin
s.ResType[s.ResCount]:="RT_FONT";
Inc(s.ResCount);
end;

if szType = RT_ACCELERATOR then
begin
s.ResType[s.ResCount]:="RT_ACCELERATOR";
Inc(s.ResCount);
end;

if szType = RT_MESSAGETABLE then
begin
s.ResType[s.ResCount]:="RT_MESSAGETABLE";
Inc(s.ResCount);
end;

if szType = RT_RCDATA then
begin
s.ResType[s.ResCount]:="RT_RCDATA";
Inc(s.ResCount);
Result := False;
end
else
Result := True;

end;


var
HLib: THandle;
h: THandle;
hres: THandle;
pnr: Pointer;
icon: TIcon;
i: Integer;
begin
s.ResCount:=0;
Memo1.Clear;
Application.ProcessMessages;

if OpenDialog1.Execute then
begin
HLib := 0;
HLib := LoadLibraryEx(PChar(OpenDialog1.FileName), 0, LOAD_LIBRARY_AS_DATAFILE);
if HLib <> 0 then
begin
Label1.Caption:=IntToStr(HLib);
//h := FindResource(HLib, nil, RT_ICON);
if not EnumResourceTypes(HLib, @EnumTypes , 0) then
MessageDlg("Not find resources", mtWarning, [mbOK], 0);

if not EnumResourceNames(HLib, RT_ICON, @EnumNames, 0) then
MessageDlg("Not find names", mtWarning, [mbOK], 0);



for i:=0 to s.ResCount-1 do
Memo1.Lines.Append(s.ResType[i] + " " + s.ResName[i]);


h := FindResource(HLib, PChar(s.ResName[0]) , "RT_ICON"); // h всегда равно 0 тк s.ResName = "" !!!!
if h = 0 then MessageDlg(IntToStr(GetLastError), mtError, [mbOK], 0);

if h <> 0 then
begin
hres := LoadResource(HLib, h);
icon := TIcon.Create;
icon.Handle := hres;
icon.SaveToFile("new.ico");
FreeResource(hres);
icon.Free;
end;
//pnr:=EnumResTypeProc(ResH);

FreeLibrary(HLib);
end;
end;
end;

end.

где же мне имя ресурса раскопать если ресурс в другом приложении ?


 
AlexRush ©   (2003-07-24 12:16) [2]

Вынеси ф-и EnumNames и EnumTypes из TForm1.Label1Click



Страницы: 1 вся ветка

Текущий архив: 2003.09.25;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.015 c
1-82274
8ung
2003-09-15 10:57
2003.09.25
Бессмертная форма.


3-82066
Новенький
2003-09-02 15:27
2003.09.25
Требуется помощь по простому запросу!


8-82337
Nikos
2003-05-25 14:03
2003.09.25
Проблема с функцией PlaySound


4-82564
mox
2003-07-21 22:09
2003.09.25
WM_GETTEXT


7-82532
Dionis
2003-07-14 16:05
2003.09.25
Опять CDROM