Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2003.09.25;
Скачать: [xml.tar.bz2];

Вниз

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 вся ветка

Форум: "WinAPI";
Текущий архив: 2003.09.25;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.018 c
14-82470
СуперТупик
2003-09-06 16:48
2003.09.25
Вирус


14-82499
HermitAlex
2003-09-05 15:20
2003.09.25
Изучение английского языка в Киеве


1-82195
Verg
2003-09-12 17:06
2003.09.25
WakeMainThread


3-82119
dream
2003-09-04 15:47
2003.09.25
Каким образом можно работать с 2 файлами баз данных ?


3-82097
P0tia
2003-09-04 20:55
2003.09.25
Как вытащить поле с датой из Excel





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский