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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the icon from an exe

Status
Not open for further replies.

ahhchu

Programmer
Sep 19, 2001
38
US
Any quick code out there that grabs the icon for a particular exe. For example when someone clicks Paint on my form I would like the icon to appear on the form..

Thanks
 
I found a code example at community.borland.com.

Look att the TI's there... Andreas Nordlund
Software developer
 
Hi Nordlund,

Can you give the exact URL please. That would be very
usefull since I am faced with the same problem.

Thanx allot,

BobbaFet Everyone has a right to my opinion.
E-mail me at cwcon@programmer.net
Be a nice guy 'n press that little ol' button
VVV---(this one) for me ;-)
 
I didn't found the link again... I have lost it...

But here's a code snippet... Hope have use of it...




var
TheIcon: TIcon;
begin
TheIcon := TIcon.Create;
TheIcon.Handle := ExtractIcon(hInstance,
'C:\SOMEPATH\SOMEPROG.EXE',
0);
{Do something with the icon}
TheIcon.Free;
end;
Andreas Nordlund
Software developer
 
Hi Nordlund,

Thanx for the reply, I'll try it out as soon as I get home.

Thanx allot,

BobbaFet Everyone has a right to my opinion.
E-mail me at cwcon@programmer.net
Be a nice guy 'n press that little ol' button
VVV---(this one) for me ;-)
 

Place TButton and TImage on the form and test this code...

uses
ShellAPI;

function GetFileIcon(FileName: string; var DocType: string): TIcon;
var
Info: SHFILEINFO;
begin
FillChar(Info, SizeOf(Info), 0);
Result := TIcon.Create;
SHGetFileInfo(PChar(FileName), 0, Info, SizeOf(Info), SHGFI_ICON or SHGFI_TYPENAME);
DocType := Info.szTypeName;
Result.Handle := Info.hIcon;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Icon: TIcon;
DocType: string;
begin
with TOpenDialog.Create(Self) do
try
if not Execute then
Exit;
Icon := GetFileIcon(FileName, DocType);
try
ShowMessage('File type: ' + DocType);
Image.Picture.Icon.Assign(Icon);
finally
Icon.Free;
end;
finally
Free;
end;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top