Процесс получения иконок из .EXE, .DLL или .ICO файлов полностью идентичен. Различие только в том, что в .ICO файле может храниться только одна иконка, а в .EXE и .DLL несколько. Для получения иконок из файлов, в модуле ShellAPI, есть функция:
function ExtractIcon(Inst: THandle; FileName: PChar; IconIndex: Word): HIcon;
где
Inst
указатель на приложение вызвавшее функцию,
FileName
имя файла из которого необходимо получить иконку,
IconIndex
номер необходимой иконки.
Если функция возвращает значение не равное нулю, то в файле есть следующая иконка.
В данном примере в компонент Image1 выводится иконка запущенного файла.
Read more »
Filed in Графика by admin | Февраль 27, 2008 | No Comments
{
Comment:
The procedure GetAssociatedIcon, trys via Registry to get the
icon(should work for small and big icons) that is associated with
the files shown in the explorer.
This is not my work. But I want to distribute it to you, because
it was really hard to find a corresonding document.
Thanks SuperTrax.
}
{
Kommentar:
Die Prozedure GetAssociatedIcon versucht uber die Registrierung
das Icon der Datei, wie im Explorer angezeigt, herauszubekommen.
(Sollte fur grosse und kleine funktionieren)
Dies ist nicht mein Werk. Ich mochte es nur fur andere zuganglich
machen, weil ich sehr lange gebraucht habe, um ein entsprechendes
Dokument zu finden.
}
Read more »
Filed in Графика by admin | Февраль 27, 2008 | No Comments
procedure TForm1.Button1Click(Sender: TObject);
var
Icon: TIcon;
FileInfo: SHFILEINFO;
begin
Icon := TIcon.Create;
try
// Get the Icon
SHGetFileInfo(PChar(’Filename.exe’), 0, FileInfo, SizeOf(FileInfo), SHGFI_ICON);
icon.Handle := FileInfo.hIcon;
DestroyIcon(FileInfo.hIcon);
// Save the Icon to a file:
icon.SaveToFile(’IconFromExe.ico’);
// Set the Icon as Application Icon (temporary)
Application.Icon := icon;
finally
Icon.Free;
end;
end;
Filed in Графика by admin | Февраль 27, 2008 | No Comments
Функция ExtractIcon позволяет извлечь иконку из exe, dll и ico-файлов. Если указанная иконка отсутствует, функция возвращает 0. Количество иконок, содержащихся в файле, можно узнать, указав в качестве последнего параметра –1.
uses ShellAPI;
procedure TForm1.Button1Click(Sender: TObject);
var
ic: TIcon;
i, count: integer;
w: integer;
begin
if OpenDialog1.Execute = false then
Exit;
Form1.Canvas.FillRect(Form1.Canvas.ClipRect);
count := ExtractIcon(Application.Handle,
PChar(OpenDialog1.FileName), -1);
ic := TIcon.Create;
w := Form1.Width div 32;
for i := 0 to count - 1 do
begin
ic.Handle := ExtractIcon(Application.Handle,
PChar(OpenDialog1.FileName), i);
Form1.Canvas.Draw(32 * (i mod w), 32 * (i div w), ic);
end;
ic.Destroy;
end;
Filed in Графика by admin | Февраль 27, 2008 | No Comments
function IconsAreEqual(const Icon1, Icon2: TIcon): Boolean;
var
ms1: TMemoryStream;
ms2: TMemoryStream;
begin
Result := False;
ms1 := TMemoryStream.Create;
try
Icon1.SaveToStream(ms1);
ms2 := TMemoryStream.Create;
try
Icon2.SaveToStream(ms2);
if ms1.Size = ms2.Size then
// Compare the streams, Streams vergleichen:
Result := CompareMem(ms1.Memory, ms2.Memory, ms1.Size)
finally
ms2.Free
end
finally
ms1.Free
end
end;
Read more »
Filed in Графика by admin | Февраль 27, 2008 | No Comments