//Bu örnek bir tür dosya gezgini örneği ama tek özelliği
//dosyaları gsterek kontrolün özel bir dosya kontrolü olmamaı
//ve dosya ve dizinlerinde orijinalleri gibi görünmesi
unit listview;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ShellAPI, StdCtrls, FileCtrl;
type
TMainForm = class(TForm)
ListView: TListView;
DirectoryListBox: TDirectoryListBox;
procedure FormCreate(Sender: TObject);
procedure DirectoryListBoxChange(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
MainForm : TMainForm;
LargeImages : TImageList;
SmallImages : TImageList;
implementation
{$R *.DFM}
procedure Createimages;
var
SysIL : uint;
SFI : TSHFileInfo;
begin
LargeImages := TImageList.Create(MainForm);
SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
if SysIL <> 0 then begin
LargeImages.Handle := SysIL;
LargeImages.ShareImages := TRUE;
end;
SmallImages := TImageList.Create(MainForm);
SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
if SysIL <> 0 then begin
SmallImages.Handle := SysIL;
SmallImages.ShareImages := TRUE;
end;
MainForm.ListView.LargeImages:=LargeImages;
MainForm.ListView.SmallImages:=SmallImages;
end;
function NamenSortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
var T1,T2 : string;
begin
T1:=Item1.Caption;
if Item1.ImageIndex=3 then
T1:='_'+T1;
T2:=Item2.Caption;
if Item2.ImageIndex=3 then
T2:='_'+T2;
Result := lstrcmp(PChar(T1),PChar(T2))
end;
procedure VerzeichnisEinlesen(VerzName:string);
var NewItem : TListItem;
Info : TSHFileInfo;
SR : TSearchRec;
begin
if VerzName[length(VerzName)]<>'\' then
VerzName:=VerzName+'\';
with MainForm do begin
ListView.Items.Clear;
if FindFirst(VerzName+'*.*',faAnyFile,SR)=0 then begin
repeat
if (length(SR.Name)>0) and (SR.Name[1]<>'.') then begin
NewItem:=ListView.Items.Add;
NewItem.Caption:=SR.Name;
SHGetFileInfo(PChar(VerzName+SR.Name),0,Info,SizeOf(TSHFileInfo),SHGFI_SYSIconIndex or SHGFI_TYPENAME);
NewItem.ImageIndex:=Info.IIcon;
NewItem.SubItems.Add(Info.szTypeName);
end;
until FindNext(SR)<>0;
FindClose(SR);
end;
ListView.CustomSort(@NamenSortProc, 0);
end;
end;
procedure TMainForm.DirectoryListBoxChange(Sender: TObject);
begin
VerzeichnisEinlesen(DirectoryListBox.Directory);
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
CreateImages;
VerzeichnisEinlesen(DirectoryListBox.Directory);
end;
end.