M_Hoeper
asked on
developing a file explorer
While developing an file explorer I have problems extracting the small icon of the associated executable file.
The large on wasn't difficult: You only have to use the api call EXTRACTASSOCIATEDICON and you will get an iconhandle. The system metrics define the size of the returned icon. This ist 32x32 with normal screen resolution.
Thanks
Marc
The large on wasn't difficult: You only have to use the api call EXTRACTASSOCIATEDICON and you will get an iconhandle. The system metrics define the size of the returned icon. This ist 32x32 with normal screen resolution.
Thanks
Marc
P.S. Add ShellApi to uses clause.
Doesn't this works :
uses ShellApi;
procedure TForm1.Button1Click(Sender : TObject);
var
IconIndex : word;
h : hIcon;
begin
IconIndex := 0;
h :=
ExtractAssociatedIcon(hIns tance,
'C:\WINDOWS\NOTEPAD.EXE',
IconINdex);
DrawIcon(Form1.Canvas.Hand le,
10,
10,
h);
Zif.
uses ShellApi;
procedure TForm1.Button1Click(Sender
var
IconIndex : word;
h : hIcon;
begin
IconIndex := 0;
h :=
ExtractAssociatedIcon(hIns
'C:\WINDOWS\NOTEPAD.EXE',
IconINdex);
DrawIcon(Form1.Canvas.Hand
10,
10,
h);
Zif.
Sorry, had a little delay. Didn't saw answer of JimBob.
ASKER
Thanks for your answer.
SHGetFileInfo doesn't work with Windows NT (4) but my program have to run with NT.
I'm sorry that I didn't write it in my question.
SHGetFileInfo doesn't work with Windows NT (4) but my program have to run with NT.
I'm sorry that I didn't write it in my question.
ShGetFileInfo does work on NT 4 (but not 3.51). I have just run a sample app on an NT 4 machine, and it didn't work 1st time. Then (without changing any code!!) I recompiled it, and ran it again and it worked... That is very odd.
The 1st time it didn't work, it didn't even add it to the image list (imgLarge.Count = 0). Maybe it didn't get a valid icon handle back. Unfortunately, I can't go back and check because every time I run it now it works fine...
JB
The 1st time it didn't work, it didn't even add it to the image list (imgLarge.Count = 0). Maybe it didn't get a valid icon handle back. Unfortunately, I can't go back and check because every time I run it now it works fine...
JB
ASKER
Oh, sorry. I looked into the help file of dephi3. They write that the SHGetFileInfo routine only works with win95.
Now, i tried a sample code and it works wonderfull... And I'm a bit confused.
Please answer the question again and you will get the 200 points.
I send the question to the windows experts, too. And they recommend to use the ExtractIconEx routine :-) This routine isn't included in the delphi help, but is integrated in the shellapi unit.
Thanks
Marc
Now, i tried a sample code and it works wonderfull... And I'm a bit confused.
Please answer the question again and you will get the 200 points.
I send the question to the windows experts, too. And they recommend to use the ExtractIconEx routine :-) This routine isn't included in the delphi help, but is integrated in the shellapi unit.
Thanks
Marc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use ShGetFileInfo to get large & small icon (and other stuff too).
E.g.
var
shfi: TShFileInfo;
Ico: TIcon;
Filename: string;
begin
Filename := 'C:\Autoexec.bat';
// Get normal (32*32) icon.
FillChar(shfi, SizeOf(TShFileInfo), 0);
ShGetFileInfo(PChar(Filena
Ico := TIcon.Create;
Ico.Handle := shfi.hIcon;
// Do something with icon, e.g. add to 32*32 TImageList:
//imgLarge.AddIcon(Ico);
Ico.Free;
// Get small (16*16) icon.
FillChar(shfi, SizeOf(TShFileInfo), 0);
ShGetFileInfo(PChar(Filena
Ico := TIcon.Create;
Ico.Handle := shfi.hIcon;
// Do something with icon, e.g. add to 16*16 TImageList:
//imgSmall.AddIcon(Ico);
Ico.Free;
Regards,
JB