Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi SmallIcon mit ExtractAssociatedIcon ??? (https://www.delphipraxis.net/13722-smallicon-mit-extractassociatedicon.html)

max666 25. Dez 2003 11:23


SmallIcon mit ExtractAssociatedIcon ???
 
Hallo!

Weiß jemand wie man mit ExtractAssociatedIcon die SmallIcons ließt.

Mit folgender Procedure erhalte ich scheinbar immer nur die LargeIcon, da die Qualität nicht sehr gut ist, wenn sie in Menu-Punkten eingebunden werden.


Delphi-Quellcode:
procedure GetIconFromFile(const FileName: String; const Index: Word);
var apbuf: array [0..2*MAX_PATH] of Char;
  aindx: Word;
  icon1: TIcon;
  icon2: HIcon;
begin
  icon1:=TIcon.Create;
  StrPCopy(apbuf, FileName);
  aindx :=index;
  icon1.Handle:= ExtractAssociatedIcon(HInstance, apbuf, aindx);
  FrmMain.ImageList2.InsertIcon(index, icon1);
end;

Gruß aus dem Emsland!
max666

[edit=Admin]Delphi-Tags ([ delphi] ... [ /delphi]) eingefügt. ;-) Künftig bitte selber machen. Danke sehr. Mfg, Daniel[/edit]

MathiasSimmack 25. Dez 2003 11:28

Re: SmallIcon mit ExtractAssociatedIcon ???
 
Ich nehme SHGetFileInfo, da kann man mit SHGFI_SMALLICON festlegen, dass man das kleine Symbol haben will.

MathiasSimmack 25. Dez 2003 17:51

Re: SmallIcon mit ExtractAssociatedIcon ???
 
Boah, da hab ich doch glatt vergessen, meinen Vorschlag zu posten.
Hier ist er, bzw. sie (die Funktion):
Delphi-Quellcode:
uses
  ShellAPI;

function GetIconFromFile(const szFilename: string;
  fSmall: boolean = false): TIcon;
const
  dwIconFlags : array[boolean]of dword =
    (SHGFI_LARGEICON,SHGFI_SMALLICON);
var
  fi : TSHFileInfo;
begin
  Result := nil;

  // Symbol der Datei aus dem System ermitteln
  // Typ (= groß/klein) richtet sich nach dem
  // Funktionsparameter "fSmall" (default = false)
  ZeroMemory(@fi,sizeof(fi));
  SHGetFileInfo(pchar(szFilename),0,fi,sizeof(fi),
    SHGFI_ICON or dwIconFlags[fSmall]);

  // Symbol ermittelt
  if(fi.hIcon <> 0) then
  begin
    Result := TIcon.Create;
    if(Result <> nil) then
      Result.Handle := fi.hIcon;
  end;
end;
Diese Funktion lädt standardmäßig die großen Symbole, was du auch am Funktionskopf erkennen kannst:
Code:
[b]function[/b] GetIconFromFile([b]const[/b] szFilename: [b]string[/b];
  [color=#ff0000]fSmall: boolean = [b]false[/b][/color]): TIcon;
D.h. du musst den zweiten Parameter nicht mal benutzen, wenn du die großen Symbole haben willst:
Delphi-Quellcode:
ImageList1.AddIcon(GetIconFromFile('c:\autoexec.bat'));
Da du aber auf die kleinen Symbole wild bist, ;), hängst du beim Aufruf einfach noch ein true an:
Code:
ImageList1.AddIcon(GetIconFromFile('c:\autoexec.bat',[color=red]true[/color]));
Das war´s.

max666 26. Dez 2003 09:15

Re: SmallIcon mit ExtractAssociatedIcon ???
 
Hallo!

Mit Deiner ersten Info konnte ich schon eine Menge anfangen, und habe das Problem auch lösen können. Aber Dein Beispiel ist auch nicht schlecht, da es eleganter programmiert ist als meines.

Danke noch einmal für Deine Antworten.

Gruß
Max


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:57 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz