Delphi-PRAXiS
Seite 1 von 4  1 23     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Problem mit Shellicons... (https://www.delphipraxis.net/5793-problem-mit-shellicons.html)

FriFra 19. Jun 2003 13:28


Problem mit Shellicons...
 
Ich benutze folgende Funktion um an den ShellIconindex zu kommen:

Delphi-Quellcode:
function TServer.GetShellIcon(FileName: string): integer;
var
  SHFileInfo: TSHFileInfo;
begin
  Result := 0;
  //Falls ein Laufwerksbuchstabe übergeben wurde...
  if Length(FileName) = 1 then
    FileName := FileName + ':';
  //Laufwerke sollten mit \ enden...
  if (Length(FileName) = 2) and (copy(FileName, length(FileName), 1) = ':') and
    (copy(FileName, length(FileName), 1) <> '\') then
    FileName := FileName + '\';
  //Dateiino lesen...
  ShGetFileInfo(PChar(FileName), 1, SHFileInfo, SizeOf(TSHFileInfo),
    SHGFI_SYSICONINDEX or SHGFI_SMALLICON or SHGFI_ICON);
  //IconIndex liefern...
  Result := SHFileInfo.iIcon
end;
Das funktioniert bei 99,9% aller Dateien wunderbar, nur z.B. bei *.htm Dateien wird das Defaulticon (unbekannte Datei) anstelle des korrekten Icons (wie im Explorer dargestellt) zurückgeliefert...

APP 19. Jun 2003 21:20

Hallo,

Delphi-Quellcode:
   SHGetFileInfo(pchar('*.htm'), FILE_ATTRIBUTE_NORMAL, sfi, sizeof(sfi),
      SHGFI_ICON OR SHGFI_USEFILEATTRIBUTES);
liefert bei mir "4" zurück, Deine Funktion liefert "0", ich kenne zwar den Index der Icons nicht, aber ich denke mal es dürfte stimmen.

Ersetzte mal den 2. Parameter (Deine 1) durch FILE_ATTRIBUTE_NORMAL und es müßte klappen...

GRUND (schlag nach bei msdn.microsoft.com):
Zitat:

pszPath
[in] Pointer to a null-terminated string of maximum length MAX_PATH that contains the path and file name. Both absolute and relative paths are valid.
If the uFlags parameter includes the SHGFI_PIDL flag, this parameter must be the address of an ITEMIDLIST (PIDL) structure that contains the list of item identifiers that uniquely identifies the file within the Shell's namespace. The pointer to an item identifier list (PIDL) must be a fully qualified PIDL. Relative PIDLs are not allowed.

If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag, this parameter does not have to be a valid file name. The function will proceed as if the file exists with the specified name and with the file attributes passed in the dwFileAttributes parameter. This allows you to obtain information about a file type by passing just the extension for pszPath and passing FILE_ATTRIBUTE_NORMAL in dwFileAttributes.

This string can use either short (the 8.3 form) or long file names.

dwFileAttributes
[in] Combination of one or more file attribute flags (FILE_ATTRIBUTE_ values as defined in Winnt.h). If uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this parameter is ignored.

FriFra 19. Jun 2003 21:30

Nein, das war's leider nicht...

http://www.frifra.de/Temp/SHI.jpg


P.S. Der IconIndex ist dynamisch, d.h. er kann variieren und hängt vom Zeitpunkt des ersten Zugriffes auf das jeweilige Icon ab. Beim Zugriff wird die SystemImageList aktualisiert und das entspr. Icon an der nächsten freien Position eingefügt.

Christian Seehase 19. Jun 2003 21:42

Moin FriFra,

hast Du mal in der Registry nachgeschaut, wie htm registriert ist?

(HKEY_CLASSES_ROOT\.htm, Standardwert, HKEY_CLASSES_ROOT\<der Standardwert von .htm>\DefaultIcon , Standardwert)

FriFra 19. Jun 2003 21:56

Das hat damit nichts zu tun... ich hab das gleiche Phänomen auf 3 Rechnern mit XP Home, XP pro und Win 2003, unter NT4 funktioniert es...

Im Windows Explorer werden die Dateien auch korrekt angezeigt. Allerdings habe ich schon div. einschlägige Democodes von verschiedenen Seiten geladen... kein Beispiel kann *.htm-icons richtig anzeigen...

flomei 19. Jun 2003 22:22

Zitat:

Zitat von FriFra
XP Home, XP pro und Win 2003

:shock: :shock: :shock: Win2003 :?: :!: Hab ich was verpasst oder meinst du Win2k (2000)

MfG Florian :hi:

Marco Haffner 19. Jun 2003 22:25

Delphi-Quellcode:
var
  SHFileInfo: TSHFileInfo;
const
  FullPath = 'D:\Eigene Dateien\Internet\HTML\Startseite\startseite.htm';
begin
  SHGetFileInfo(FullPath, 0, SHFileInfo, SizeOf(SHFileInfo), SHGFI_ICON);
  Image1.Picture.Icon.Handle := SHFileInfo.hIcon;
end;
zeigt bei mir das html Icon an, aber nur wenn bei FullPath auch ein vollständiger Dateiname (incl. Pfad) angegeben wurde, *.htm alleine reicht nicht.

Zitat:

Zitat von flomei
Zitat:

Zitat von FriFra
XP Home, XP pro und Win 2003

:shock: :shock: :shock: Win2003 :?: :!: Hab ich was verpasst oder meinst du Win2k (2000)

Nein er meint wirklich Windows 2003. Heißt aber glaub' ich komplett Windows Server 2003

APP 19. Jun 2003 22:30

Zitat:

Zitat von FriFra
Nein, das war's leider nicht...

http://www.frifra.de/Temp/SHI.jpg

also ich kenne Deinen Code nicht genau, aber wenn ich zuerst
Delphi-Quellcode:
   SHGetFileInfo(pchar('*.htm'), FILE_ATTRIBUTE_NORMAL, sfi, sizeof(sfi),
      SHGFI_ICON OR SHGFI_USEFILEATTRIBUTES);
   showmessage(inttostr(sfi.iIcon));
und mir danach die SystemImageListe mit
Delphi-Quellcode:
PROCEDURE GetSystemImageList(ImageList: TImageList);
VAR
   res                            : Integer;
   shf                            : TSHFILEINFO;
BEGIN
   res := SHGetFileInfo('', 0, shf, SizeOf(shf), SHGFI_SYSICONINDEX OR SHGFI_SMALLICON);
   ImageList.handle := Res;
   ImageList.ShareImages := True;
END;
--------------------------------

VAR
   I                              : Integer;
   ListItem                       : TListItem;
BEGIN
   GetSystemImageList(Imagelist1);
    BEGIN
      WITH ListView1 DO
         BEGIN
            SmallImages := ImageList1;
            LargeImages := ImageList1;
            FOR I := 0 TO ImageList1.Count - 1 DO
               BEGIN
                  ListItem := Items.Add;
                  ListItem.ImageIndex := I;
               END;
          END;
   END;
hole ist das Html Icon an 5. Stelle = 4. Index.

Daniel B 19. Jun 2003 22:31

Zitat:

Zitat von flomei
:shock: :shock: :shock: Win2003 :?: :!: Hab ich was verpasst oder meinst du Win2k (2000)

Wie Marco es schon sagte, es handelt sich dabei um den Server! Der Nachfolger von 2000 wird dann 2004/2005 kommen und dann LongHorn heissen. :mrgreen:

Grüsse, Daniel :hi:

FriFra 19. Jun 2003 22:37

Der Code sieht etwas anders aus (s. Eröffnungspost)...

Ich ermittle lediglich den ImageIndex des Icons. OnCreate habe ich zwei ImageLists das handle der Large-, bzw. SmallIconlist zugewiesen. Beim Aufruf meiner Funktion wird dann nur bei Bedarf ein neues Imagge in die Imagelist eingefügt, bzw. der Index des schon vorhandenen Images geliegfert - eine andere Vorgenensweise (direkter Zugriff auf das Icon) ist nicht performant, bzw. mit keinem heutigem Rechner durchführbar, da die Ressourcen extrem schnell verbraucht wären...

P.S.: Ich übergebe immer den kompletten Pfad exisistierender Dateien.
Ja, ich meine den Server 2003 (hab ich im Keller stehen :dancer: )


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:46 Uhr.
Seite 1 von 4  1 23     Letzte »    

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