Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract icon from File

Status
Not open for further replies.

Nordlund

Programmer
Jul 17, 2001
458
SE
Hi.
For a while ago, someone wrote how to extract icons from files.

The default Icon for Notepad is icon number 70 from Shell32.dll.

But how the heck do I extract 70 from the registry?

I have extracted the following row from the Registry:
%SystemRoot%\system32\shell32.dll,-152

The Icon Index is -152... But how do the system know to use Index 70?


//Nordlund
 
Try the windows API function ExtractIcon()

var
MyIcon: TIcon;
begin
MyIcon := TIcon.Create;
MyIcon.Handle := ExtractIcon(hInstance, 'C:\SOMEPATH\SOMEPROG.EXE',0);
{Do whatever with the icon}
MyIcon.Free;
end;


Ryan
 
The little utility I use for borrowing ;-) icons:

Drop 1 TEdit (edtFilename) 1 TImage (imgIcon) and 1 TButton and put the following code on button click.

Code:
var
  IconIndex: word;
  Buffer: array[0..2048] of char;
  IconHandle: HIcon;
begin
  StrCopy(@Buffer, PChar(edtFilename.Text));
  IconIndex := 0;
  IconHandle := ExtractAssociatedIcon(HInstance, Buffer, IconIndex);
  if IconHandle <> 0 then
    Icon.Handle := IconHandle;

  imgIcon.Picture.Icon.Handle := IconHandle;
  ImgIcon.Picture.SaveToFile('c:\temp.ico');
end;

Robertio
Alias: Robbie Calder
Software Developer
urc@walkermartyn.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top