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 Problem mit SHGetFileInfo und SHGFI_ICONLOCATION (https://www.delphipraxis.net/53265-problem-mit-shgetfileinfo-und-shgfi_iconlocation.html)

Thebe 13. Sep 2005 11:24


Problem mit SHGetFileInfo und SHGFI_ICONLOCATION
 
Moin

Ich hab folgenden Code

Delphi-Quellcode:
var
  fi: SHFileInfo;
begin
  AFile := 'C:\irgendeine.bmp';

  SHGetFileInfo(pChar(AFile), 0, fi, SizeOf(fi), SHGFI_ICONLOCATION)

  // SHGFI_ICONLOCATION = Retrieve the name of the file that contains the icon representing the file specified by pszPath, as returned by the IExtractIcon::GetIconLocation method of the file's icon handler. Also retrieve the icon index within that file. The name of the file containing the icon is copied to the szDisplayName member of the structure specified by psfi. The icon's index is copied to that structure's iIcon member.
end;
Problem ist nur: szDisplayName beinhaltet nicht wider Erwarten nach der MSDN den Namen der Datei, wo das Icon abgespeichert is, sondern ist einfach nur leer. Ich habe erst gedacht ich hätte bei der weiteren Weiterverarbeitung nen Fehler beim Typecast gemacht, doch nachhem gesetzten Haltepunkt zeigt Delphi mir auch an das fi.szDisplayName komplett leer ist.

Woran kann sowas liegen ? Bin ich zu blöd nu drei bzw. vier Parameter zu übergeben oder liegt das anner WinAPI ?

MfG
- Thebe

Thebe 15. Sep 2005 17:17

Re: Problem mit SHGetFileInfo und SHGFI_ICONLOCATION
 
*schiiiieeeb*

Keiner ne Ahnung woran das liegen könnte ??

Luckie 15. Sep 2005 17:30

Re: Problem mit SHGetFileInfo und SHGFI_ICONLOCATION
 
Was hast du denn für eine Datei angegeben?

Union 15. Sep 2005 18:02

Re: Problem mit SHGetFileInfo und SHGFI_ICONLOCATION
 
Zitat:

Zitat von Thebe
Moin

Ich hab folgenden Code

Delphi-Quellcode:
var
  fi: SHFileInfo;
begin
  AFile := 'C:\irgendeine.bmp';

  SHGetFileInfo(pChar(AFile), 0, fi, SizeOf(fi), SHGFI_ICONLOCATION)

  // SHGFI_ICONLOCATION = Retrieve the name of the file that contains the icon representing the file specified by pszPath, as returned by the IExtractIcon::GetIconLocation method of the file's icon handler. Also retrieve the icon index within that file. The name of the file containing the icon is copied to the szDisplayName member of the structure specified by psfi. The icon's index is copied to that structure's iIcon member.
end;
Problem ist nur: szDisplayName beinhaltet nicht wider Erwarten nach der MSDN den Namen der Datei, wo das Icon abgespeichert is, sondern ist einfach nur leer. Ich habe erst gedacht ich hätte bei der weiteren Weiterverarbeitung nen Fehler beim Typecast gemacht, doch nachhem gesetzten Haltepunkt zeigt Delphi mir auch an das fi.szDisplayName komplett leer ist.

Woran kann sowas liegen ? Bin ich zu blöd nu drei bzw. vier Parameter zu übergeben oder liegt das anner WinAPI ?

MfG
- Thebe

Naja, ein bischen logisch denken wäre nicht soo schlecht ;)
Delphi-Quellcode:
  SHGetFileInfo(pChar(AFile), 0, fi, SizeOf(fi), SHGFI_ICONLOCATION or SHGFI_TYPENAME or SHGFI_DISPLAYNAME);
  ShowMessage('Displayname: '+strpas(fi.szDisplayName)+#13+
              'Typename: '+strpas(fi.szTypeName)+#13+
              'IIcon: '+IntToStr(fi.IIcon));
  if fi.hIcon > 0 then
     DestroyIcon(fi.hIcon);
Wenn Du im Member DisplayName was drinstehen haben möchtest, dann musst Du das der Funktion auch in den Flags (SHGFI_DISPLAYNAME) mitteilen. Das DestroyIcon sollte man auch nicht vergessen, wenn man im Rahmen von Spielereien mal SHGFI_ICON verwendet...

Thebe 15. Sep 2005 21:22

Re: Problem mit SHGetFileInfo und SHGFI_ICONLOCATION
 
@Luckie: PDF, BMP u. XLS Dateien von meiner Festplatte, Pfad war korrekt und die Dateien waren existent.

@Union:

Zitat:

Naja, ein bischen logisch denken wäre nicht soo schlecht
Ähm... hab ich, hab ich...

Ma ne Beschreibung von SHGFI_DISPLAYNAME vonna MSDN Seite:
Zitat:

SHGFI_DISPLAYNAME
Retrieve the display name for the file. The name is copied to the szDisplayName member of the structure specified in psfi. The returned display name uses the long file name, if there is one, rather than the 8.3 form of the file name.
Sprich das Ding gibt mir nur den Dateinamen für die Datei zurück, so wie er im Explorer angezeigt wird. Wenn ich also SHGetFileInfo als Pfad "C:\irgendeine.bmp" übergebe, dann krieg ich als szDisplayName "irgendeine.bmp" wieder und nicht die Datei, in der das Icon für .bmp Dateien abgespeichert ist. :(

Aber danke für die Antwort :)

blablab 29. Dez 2012 04:53

AW: Problem mit SHGetFileInfo und SHGFI_ICONLOCATION
 
Ich hab 1:1 dasselbe Problem. Gibt es inzwischen eine Lösung?

Mschmidt 3. Jan 2013 16:24

AW: Problem mit SHGetFileInfo und SHGFI_ICONLOCATION
 
Ich hab hier was. Ich brauch das Icon der Datei. Vielleicht hilfts.

Delphi-Quellcode:
function GetGenericIconIndex( AExtension: string ): integer;
{ Get icon index for an extension type }
var
  AInfo: TSHFileInfo;
begin
  if SHGetFileInfo( PChar( AExtension ), FILE_ATTRIBUTE_NORMAL, AInfo, SizeOf( AInfo ),
    SHGFI_SYSICONINDEX or SHGFI_LARGEICON or SHGFI_USEFILEATTRIBUTES ) <> 0 then
  Result := AInfo.iIcon
  else
    Result := -1;
end;

procedure BuildImageList;
var FileInfo: TSHFileInfo;
 dw:DWORD;
begin
  Inherited Create(AOwner);
  fImageList:= TImageList.Create(self);
  dw:=SHGetFileInfo('', 0, FileInfo, SizeOf(TSHFileInfo),
      SHGFI_LARGEICON or SHGFI_SYSICONINDEX );
  if dw>0 then begin
    fImageList.Width:= 32;
    fImageList.Height:=32;
    fImageList.ShareImages:= True;
    fImageList.Handle:= dw;
    List.LargeImages:= fImageList;// is a TListView !
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:13 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