function OpenFolder(sAddress: string; LF:TListView); var hFile:TSearchRec; itm:TListitem; begin if Copy(sAddress,Length(sAddress),1)<>'\' then sAddress:=sAddress + '\'; if FindFirst((sAddress + '*.*'),FaAnyFile,hFile) <> 0 then begin Application.MessageBox(PChar('无法打开指定目录:'#13#10 + sAddress),'错误',MB_ICONSTOP); exit; end; SendMessage(LF.Handle,LVM_SETIMAGELIST,LVSIL_SMALL,SHGetFileInfo('C:\',0,FInfo,SizeOf(FInfo),SHGFI_SYSICONINDEX or SHGFI_SMALLICON)); SendMessage(LF.Handle,LVM_SETIMAGELIST,LVSIL_NORMAL,SHGetFileInfo('C:\',0,FInfo,SizeOf(FInfo),SHGFI_SYSICONINDEX or SHGFI_LARGEICON)); end; LF.Items.BeginUpdate; LF.Items.Clear; FindNext(hFile); while FindNext(hFile)=0 do begin SHGetFileInfo(PChar(sAddress + hFile.Name),0,FInfo,SizeOf(FInfo),SHGFI_SYSICONINDEX or SHGFI_SMALLICON); itm:=LF.Items.Add; itm.Caption:=hFile.Name; itm.ImageIndex:=FInfo.iIcon; end; FindClose(hFile); LF.Items.EndUpdate; LF.SetFocus; end;
var
hFile:TSearchRec;
itm:TListitem;
begin
if Copy(sAddress,Length(sAddress),1)<>'\' then sAddress:=sAddress + '\';
if FindFirst((sAddress + '*.*'),FaAnyFile,hFile) <> 0 then
begin
Application.MessageBox(PChar('无法打开指定目录:'#13#10 + sAddress),'错误',MB_ICONSTOP);
exit;
end; SendMessage(LF.Handle,LVM_SETIMAGELIST,LVSIL_SMALL,SHGetFileInfo('C:\',0,FInfo,SizeOf(FInfo),SHGFI_SYSICONINDEX or SHGFI_SMALLICON));
SendMessage(LF.Handle,LVM_SETIMAGELIST,LVSIL_NORMAL,SHGetFileInfo('C:\',0,FInfo,SizeOf(FInfo),SHGFI_SYSICONINDEX or SHGFI_LARGEICON));
end;
LF.Items.BeginUpdate;
LF.Items.Clear;
FindNext(hFile);
while FindNext(hFile)=0 do
begin
SHGetFileInfo(PChar(sAddress + hFile.Name),0,FInfo,SizeOf(FInfo),SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
itm:=LF.Items.Add;
itm.Caption:=hFile.Name;
itm.ImageIndex:=FInfo.iIcon;
end;
FindClose(hFile);
LF.Items.EndUpdate;
LF.SetFocus;
end;