Bonjour,
j'ai ça :
Comment faire pour obtenir l'icône associé a chaque fichier ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 fichier1 := 'toto.txt' ; fichier2 := 'toto.jpg' ;
Merci
Bonjour,
j'ai ça :
Comment faire pour obtenir l'icône associé a chaque fichier ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 fichier1 := 'toto.txt' ; fichier2 := 'toto.jpg' ;
Merci
J'ai trouvé ca (pas testé):
Je recupère l'icone associé au fichier texte par cette méthode:
Code:
function GetAssociatedIcon(const Ext: PChar): HICON;
var
Info: TSHFileInfo;
begin
SHGetFileInfo(Ext, FILE_ATTRIBUTE_NORMAL, Info, SizeOf(Info), SHGFI_ICON or SHGFI_SMALLICON or SHGFI_USEFILEATTRIBUTES);
Result := Info.hIcon;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Ic: TIcon;
begin
Ic := TIcon.Create;
Ic.Handle := GetAssociatedIcon('.txt');
ImageList1.AddIcon(Ic);
ImageList1.Draw(Image1.Canvas, 0, 0, 0, True);
Ic.Free;
end;![]()
L'urgent est fait, l'impossible est en cours, pour les miracles prévoir un délai. :bug: ___ "http://club.developpez.com/regles/#LIII-A"Écrivez dans un français correct !!
C++Builder 5 - Delphi 6#2 Entreprise - Delphi 2007 Entreprise - Delphi 2010 Architecte - Delphi XE Entreprise - Delphi XE7 Entreprise - Delphi 10 Entreprise - Delphi 10.4.2 Entreprise - Delphi 11.3 Entreprise - Visual studio 2022
OpenGL 2.1 - Oracle 10g - Paradox - Interbase (XE) - PostgreSQL (15.7)
moi j'utilise ça :
(ne pas oublier de faire un Free du TIcon renvoyé lorsqu'il n'est plus utile)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 function GetIcon(const FileName: string; const Large: Boolean): TIcon; var sfi: TSHFILEINFO; i: Integer; begin Result := nil; try Result := TIcon.Create; if Large then i := SHGFI_LARGEICON else i := SHGFI_SMALLICON; SHGetFileInfo(PChar(FileName), FILE_ATTRIBUTE_NORMAL, sfi, SizeOf(sfi), SHGFI_ICON or SHGFI_USEFILEATTRIBUTES or i); Result.Handle := sfi.hIcon; except if Result <> nil then FreeAndNil(Result); end; end;
c'est à peu près pareil sauf qu'ici on a l'icône pour un fichier précis (par ex les .exe et .lnk ont souvent des icônes différentes pour chaque fichier)
Merci, mais ça marche pas : il me dit :
[Erreur] fonctions.pas(40): Identificateur non déclaré : 'FILE_ATTRIBUTE_NORMAL'
pour ça :Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part SHGetFileInfo(PChar(FileName), FILE_ATTRIBUTE_NORMAL, sfi, SizeOf(sfi), SHGFI_ICON or SHGFI_USEFILEATTRIBUTES or i);
Tu as bien Windows dans tes uses ?
![]()
L'urgent est fait, l'impossible est en cours, pour les miracles prévoir un délai. :bug: ___ "http://club.developpez.com/regles/#LIII-A"Écrivez dans un français correct !!
C++Builder 5 - Delphi 6#2 Entreprise - Delphi 2007 Entreprise - Delphi 2010 Architecte - Delphi XE Entreprise - Delphi XE7 Entreprise - Delphi 10 Entreprise - Delphi 10.4.2 Entreprise - Delphi 11.3 Entreprise - Visual studio 2022
OpenGL 2.1 - Oracle 10g - Paradox - Interbase (XE) - PostgreSQL (15.7)
Ça marche, merci !
En effet, il me manquait Windows...
Partager