类似资源管理器的东西, 图标出现多个,做了很久了还没解决,望各位大大帮个忙~!(300)

  • 主题发起人 lastforest
  • 开始时间
L

lastforest

Unregistered / Unconfirmed
GUEST, unregistred user!
类似资源管理器的东西, 图标出现多个,做了很久了还没解决,望各位大大帮个忙~!我的目的是吧多个文件夹下的文件,都添加到listview中。关键代码如下:function TFilesFrm.Addfile(strPath: string; pathMask:string;ListView: TListView): boolean; var Msize: Integer; Icon:Ticon; SysList:Thandle; a:_WIN32_FIND_DATA; b:longint; ListItem: TListItem; FileInfo: SHFILEINFO; temp:string; Mtime:Tsystemtime; begin // Create a temporary TIcon try //shIcon := 0; lhIcon := 0; Temp:=strpath; ListView.Items.BeginUpdate; // search for the first file b := findfirstfile(pchar(strpath +pathmask),a); // count := ExtractIconEx( a.cFileName , -1, lhIcon, shIcon, 0 ); while findnextFile(b,a)=true do begin if (a.dwFileAttributes<>49)or(a.dwFileAttributes<>48)or (a.dwFileAttributes<>16) AND (trim(a.cFileName)<>'.')and(trim(a.cFileName)<>'..')and(trim(a.cFileName)<>'')then begin with ListView do begin ListItem := ListView.Items.Add; Listitem.Caption := A.cFileName; listitem.SubItems.Add(strpath); Msize:=a.nFileSizeLow div 1024; if Msize=0 then Msize:=1; listitem.SubItems.Add(inttostr(Msize)); filetimetosystemtime(a.ftLastWriteTime,Mtime); listitem.SubItems.Add(datetimetostr(systemtimetodatetime(Mtime))); end ; //图标处理; 主要是一下代码出现问题。。。 图标出现多个 Icon := TIcon.Create; Icon.Handle:=getLargeIcon(strpath+a.cFileName); large.AddIcon(Icon); listview.LargeImages:=Large; Large.ShareImages:=true; ListView.Items.Add.ImageIndex:=large.Count -1 ; Icon.Handle:=getSmallIcon(strpath+a.cFileName); small.AddIcon(Icon); listview.SmallImages:=small; small.ShareImages:=true; ListView.Items.Add.ImageIndex:=small.Count -1 ; end else if ((a.dwFileAttributes=49)or(a.dwFileAttributes=48)or a.dwFileAttributes=16))and(trim(a.cFileName)<>'.')and(trim(a.cFileName)<>'..') then addfile(Pchar(TRIM(Temp)+a.cFileName),pathmask,listview); //递归 end; finally Icon.Free; ListView.Items.EndUpdate; // Destroy the Icon DestroyIcon(FileInfo.hIcon); end; end; function TFilesFrm.GetLargeIcon(FileName: string): Integer; //获取大图标var FileInfo: TSHFileInfo; begin FillChar(FileInfo, SizeOf(FileInfo), #0); SHGetFileInfo(PChar(FileName), 0, FileInfo, SizeOf(FileInfo), shgfi_icon or SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES ); Result := FileInfo.hIcon; end;function TFilesFrm.GetSmallIcon(FileName: string): Integer; // 获取小图标var FileInfo: TSHFileInfo; begin FillChar(FileInfo, SizeOf(FileInfo), #0); SHGetFileInfo(PChar(FileName), 0, FileInfo, SizeOf(FileInfo), shgfi_icon or SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES or SHGFI_SmallICON ); Result := FileInfo.hIcon; end;但是 运行后 listview中的每个文件的图标有3个之多,而我只要一个即可,怎么解决?
 
很难吗? 怎么没一个人回答啊?
 
D7 里有有关 TListView 的 Demo
 
你只单独添加大图标,或单独添加小图标看看情况
 
现在大富翁没落到这种程度了吗,我在盒子上发都有很多人回,在这里程序都没人看看吗?至少帮我看看程序啊 ~!
 
路过帮顶!
 
// ListView.Items.Add.ImageIndex:=large.Count -1 ;// Icon.Handle:=getSmallIcon(strpath+a.cFileName);// small.AddIcon(Icon);// listview.SmallImages:=small;// small.ShareImages:=true;// ListView.Items.Add.ImageIndex:=small.Count -1 ;注释掉
 
接收答案了~!自己解决了
 
顶部