Forum > Win32/64

Associate files and icons, in Listview

<< < (2/2)

Ericktux:
thanks to all, this works fine with transparency   :D :D


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  windows, ShellApi, Classes, SysUtils, FileUtil, Forms, Controls, Graphics,  Dialogs, ComCtrls, StdCtrls, LazUTF8, CommCtrl; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    ImageList1: TImageList;    ListView1: TListView;    procedure Button1Click(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  spath: string;  SysStr: Widestring;  i: integer;  mIcon: TIcon;  SearchRec: TSearchRec;  ListItem: TListItem;  FileInfo: SHFILEINFOw;begin   sPath := 'C:\Files';  // ejem:  "f:"   รณ   "sPath := 'C:\Documents and Settings\Propietario\Recent'";  if sPath[Length(sPath)]<>'\' then sPath := sPath+'\';  // agregar el slash si es ncesario  ListView1.SmallImages := ImageList1;  ListView1.ViewStyle := vsReport;  ListView1.Columns.Add;  ListView1.Columns.Add;  mIcon := TIcon.Create;  //mIcon.Transparent:=true;  try    ListView1.Items.BeginUpdate;    i := FindFirst(sPath + '*.*', faAnyFile, SearchRec);    while i = 0 do      begin        application.ProcessMessages;        with ListView1 do        begin        //if ((SearchRec.Attr and FaDirectory <> FaDirectory) and (SearchRec.Attr and FaVolumeId <> FaVolumeID)) then   // for only files        If (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then          Begin          // ShowMessage(sPath+SR.Name);   // mostrar el archivo encontrado ejem:     f:\casas\hola.txt     SR.Name=hola.txt          SysStr := UTF8ToUTF16(sPath + SearchRec.Name);          SHGetFileInfoW(PWideChar(SysStr), 0, FileInfo, SizeOf(FileInfo), SHGFI_DISPLAYNAME or SHGFI_TYPENAME or SHGFI_ICON or SHGFI_SMALLICON);          ListItem := ListView1.Items.Add;          Listitem.Caption := UTF16ToUTF8(FileInfo.szDisplayName);          ListItem.SubItems.Add(UTF16ToUTF8(FileInfo.szTypeName));          mIcon.Handle := FileInfo.hIcon;           ListItem.ImageIndex := ImageList1.AddIcon(mIcon); // original          ListItem.ImageIndex := ImageList_ReplaceIcon(ImageList1.Handle, ListItem.ImageIndex, micon.Handle);        end;       end;      i := FindNext(SearchRec);    end;  finally    ListView1.items.EndUpdate;    mIcon.Free;  end;end; end.


Aqdam1978@yahoo.com:
I just check the code, it's still showing error since there is no HANDLE property available for the ImageList. How you did claim that code works fine????

GetMem:

--- Quote from: Aqdam1978@yahoo.com on September 07, 2021, 04:35:58 am ---How you did claim that code works fine????

--- End quote ---

When the OP posted the code it worked fine, since then things has changed. Instead of  ImageList1.Handle try:
 
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- ImageList1.ResolutionByIndex[0].Reference.Handle
or even better
 
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ImageList1.ReferenceForPPI[0, Font.PixelsPerInch].Handle
 and make sure CommCtrl is in the uses list.

With that said OP's code is very slow, just search the forum, there are much faster solutions available.

Navigation

[0] Message Index

[*] Previous page

Go to full version