size : 847
uploaded_on : Tue Oct 6 00:00:00 1998
modified_on : Wed Dec 8 14:03:13 1999
title : Extracting Icons
org_filename : extracticon.txt
author : Billy
authoremail : billycrazy@my-dejanews.com
description : Extract icons from DLLs and EXEs
keywords :
tested : not tested yet
submitted_by : The CKB Crew
submitted_by_email : ckb@netalive.org
uploaded_by : nobody
modified_by : nobody
owner : nobody
lang : plain
file-type : text/plain
category : delphi-graphics
__END_OF_HEADER__
> I need to know how to extract icons from DLLs and EXEs using code.
Try this:
// must use ShellApi here
uses
......., ShellApi;
.......
// Get total number of icons in a file
function GetTotalIcon(const filename: string): integer;
begin
result := ExtractIcon(HInstance,PChar(fileName),-1);
end;
// index = 0 for the first icon, and 0 <= index < total
function GetIconFromFile(index: integer; const fileName: string): TIcon;
var
aHandle: HIcon;
aIcon: TIcon;
begin
aHandle := ExtractIcon(HInstance,PChar(fileName),index);
// see Win32.hlp on ExtractIcon for detail on return values
if (aHandle = 1) then
raise Exception.Create('No icon in ' + fileName)
else if (aHandle = 0) then
raise Exception.Create('Not supported file: ' + fileName);
aIcon := TIcon.Create;
aIcon.Handle := aHandle;
result := aIcon;
end;