mozes preko API-ja da dobijes handle od sistemskog listView-a koji sadrzi sve ikonice (osim ikona koje predstavljaju ikone - znaci samo ikone za registrovane tipove), to brzo radi koliko znam. takodje koristis api funkcije da dobijes ImageIndex ikone za odredjeni fajl. Nemam bas pri sebi taj kod ali sam vidjao po netu. Ja imam neki ali ne radi bas najbolje na XP-u. Drugi nacin je (tako sam ja radio u jednom svom programu) da dinamicki pravis ListView tako sto svaki put kad otvoris neki direktorijum proveravas da li u listview do tad postoji ikonica za taj tip ili ne. ako nema onda preko API-ja uzmes ikonicu i ubacis je u listview.
Evo koda za to
Code:
function TMainForm.GetSmallIcon(Name: string): Integer;
var
FileInfo: TSHFileInfo;
aIcon: TIcon;
begin
// clear the memory
FillChar(FileInfo, SizeOf(FileInfo), #0);
// get a handle to the ImageList for the file selected
SHGetFileInfo(PChar(Name), 0, FileInfo, SizeOf(FileInfo),
SHGFI_ICON or SHGFI_SMALLICON or SHGFI_SHELLICONSIZE);
aIcon := TIcon.Create;
// assign the handle of the icon returned
aIcon.Handle := FileInfo.hIcon;
// lets paint it transparent
aIcon.Transparent := True;
if Name[Length(Name)] = '\' then //za folder
ObjectIconsSmall.ReplaceIcon(0, aIcon)
else
Result := ObjectIconsSmall.AddIcon(aIcon); //za fajl
// free our icon class
FreeAndNil(aIcon);
DestroyIcon(FileInfo.hIcon);
end;
analogno za vece ikone, koristi flag SHGFI_LARGEICON,, rezultat je ImageIndex dodate ikone
uzgred, mozda ne znas, ali na XP-u moras da konvertujes ImageList u 32bitni format da bi mogao da stavljas XP-ove fancy ikone sa alpha kanalom. To se radi ovako
Code:
procedure TMainForm.ConvertTo32BitImageList(const ImageList: TImageList);
const
Mask: array[Boolean] of Longint = (0, ILC_MASK);
var
TemporyImageList: TImageList;
begin
if Assigned(ImageList) then
begin
TemporyImageList := TImageList.Create(nil);
try
TemporyImageList.Assign(ImageList);
with ImageList do
begin
ImageList.Handle := ImageList_Create(Width, Height, ILC_COLOR32 or Mask[Masked], 0, AllocBy);
if not ImageList.HandleAllocated then
begin
raise EInvalidOperation.Create(SInvalidImageList);
end;
end;
ImageList.AddImages(TemporyImageList);
finally
TemporyImageList.Free;
end;
end;
end;
nadam se da ima vajde od ovoga :)
Ride the rainbow, crack the sky
DIY gitare, pojacala i efekti
www.diy-fever.com