Registriert seit: 31. Okt 2003
1.120 Beiträge
Delphi 7 Personal
|
Re: ICL in TImageList laden
16. Jan 2004, 12:27
Habs mal erweitert, jetzt fügt er alle Icons ein:
Delphi-Quellcode:
function ResourcenameCallBack(Module:HModule;resTyp:Pchar;resname:Pchar;list: TStrings):Integer;stdcall;
begin
if HiWord(Cardinal(resname)) <> 0 then
list.Add(' ' + resname)
else
list.Add(Format(' #%d', [loword(Cardinal(resname))]));
Result := 1;
end;
function CheckResName(const AName : String) : PChar;
begin
If (Pos(' #', AName) = 1) then
result := MakeIntResource(StrToInt(Copy(Aname, 3, length(AName))))
else
result := PChar(AName);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
AIco : TIcon;
hDLL : THandle;
IcoList : TStringList;
i : integer;
begin
Button1.Enabled := false;
hDLL := LoadLibraryEx(PChar(Edit1.Text), 0, LOAD_LIBRARY_AS_DATAFILE);
IcoList := TStringList.Create;
try
//ImageList1.Clear;
EnumResourceNames(hDLL, RT_GROUP_ICON, @ResourcenameCallBack, Integer(IcoList));
for i := 0 to IcoList.Count-1 do
begin
AIco := TIcon.Create;
try
AIco.Handle := LoadImage(hDLL, CheckResName(IcoList[i]), IMAGE_ICON, ImageList1.Width, ImageList1.Height, LR_DEFAULTCOLOR);
ImageList1.AddIcon(AIco);
finally
AIco.Free;
end;
end;
finally
IcoList.Free;
FreeLibrary(hDLL);
end;
Button1.Enabled := true;
end;
|
|
Zitat
|