Autor Beitrag
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mi 10.08.05 17:11 
Ich versuche seit einigen Stunden erfolglos das Icon (16x16) einer Datei in eine ImageList zu bekommen.

Bisher habe ich versucht mit SHGetFileInfo und SHGFI_ICON or SHGFI_SMALLICON das Handle dieses Icons zu bekommen, um dieses an ein TIcon zu übergeben, welches dann über AddIcon in die ImageList aufgenommen wird. Leider werden bei 32Bit Symbolen hässliche schwarze Ränder angezeigt. Der Alphakanal geht hier irgendwo verloren.

Um das zu umgehen habe ich den Parameter uFlags auf SHGFI_ICONLOCATION geändert. Laut PSDK sollte nun die Quelle des Icons und der IconIndex übergeben werden. Der IconIndex stimmt, aber leider kommt keine Icondatei. Die Variable ist mit #0 gefüllt.

Mache ich hier irgendwo einen Fehler, oder kann mir jemand erklären, warum ich von Hand in der IDE 32Bit Icons in eine ImageList einfügen kann, zur Laufzeit aber nicht?

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 10.08.05 20:00 
Hallo,

das liest alle SystemIcons in eine ImageList ein und gibt das bmp-Icon auf der Canvas aus.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
var  SysIL : HImageList;
     Info : TSHFileInfo;
     aIcon : TIcon;
begin
  SysIL := SHGetFileInfo('', 0, Info, SizeOf(Info),
                         SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  SHGetFileInfo(PChar('.bmp'), FILE_ATTRIBUTE_NORMAL, Info, SizeOf(TShFileInfo),
                SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES);
  if SysIL <> 0 then
  begin
    ImageList1.Handle := SysIL;
    ImageList1.ShareImages := True;
    ImageList1.Draw(Canvas,20,20,Info.iIcon);
  end;

Ob das genau das ist was Du suchst :gruebel:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
derDoc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mi 10.08.05 21:29 
Danke schonmal für den Vorschlag, ich teste das gleich.

Mein Problem genau ist, dass ich mit meinem Programm eine Datei öffne (z.B. Datei.rar) und nun deren zugeordnetes Icon (16x16) in einer ImageList habe will, um dieses in einer ListView anzeigen zu können. Leider bekomme ich nur Icons in geringer Farbtiefe (mit schwarzen Rändern statt Schatten) in die ImageList.

Wenn ich über die IDE einer ImageList ein 32Bit Icon hinzufüge, wird dieses auch ordentlich angezeigt. Wenn ich aber ein solchen Icon über ImageList.AddIcon() hinzufüge, verliert es den Alphakanal.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 10.08.05 21:46 
Hallo,

hier ein Code zum initialisieren der System-Icons:
Icons für die ListView initialisieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.InitialisiereIcons;
  var SysIL       : HImageList;
      Info        : TSHFileInfo;
      SmallImages : TImageList;
begin
  SmallImages := TImageList.Create(Form1);
  SysIL := SHGetFileInfo('', 0, Info, SizeOf(SFI),
           SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  if SysIL <> 0 then
    begin
    SmallImages.Handle := SysIL;
    SmallImages.ShareImages := TRUE;
    ListView1.SmallImages := SmallImages;
    end;
end;


dann anzeigen im ListView:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var Newitem  : TListItem;
    Info     : TSHFileInfo;
begin
  NewItem := ListView1.Items.Add;
  NewItem.Caption := 'Datei.rar';
  //FILE_ATTRIBUTE_NORMAL Icon ohne vollständigen Pfad ermitteln
  SHGetFileInfo(PChar(NewItem.Caption)
               ,FILE_ATTRIBUTE_NORMAL, Info, SizeOf(TShFileInfo),  
                SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES);
  NewItem.ImageIndex := Info.IIcon;

damit habe ich bei mir keine Probleme.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
derDoc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mi 10.08.05 22:04 
Danke,

damit klappt es endlich.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.