SHGetFileInfo()其中有一个大图标的的参数

解决方案 »

  1.   

    我自己回答吧,用API函数 
    ExtractIconEx(
        LPCSTR lpszFile,
        int nIconIndex,
        HICON FAR * phiconLarge,
        HICON FAR * phiconSmall,
        UINT nIcons 
       );
      

  2.   

    procedure TForm1.ExtractFileIcon(const FileName: string);
    var
      i: integer;
    begin
      i := 0;
      Image1.Picture.Icon.handle := ExtractIcon(Hinstance, Pchar(FileName), i);
    end;
      

  3.   

    以上是取一个图标显示在TImage中,下面是提取所有的图标显示在ListView中
    首先,在窗体放一个ImageList,Width and Height = 32,放一个ListView,LargeIcon属性设为ImageList1,为了好看,再窗体底部放一个ProgressBar,align= alBottom
    procedure TForm1.ExtractFileIcon(const FileName: string);
    var
      i, iCount: integer;
      Icon: TIcon;
    begin
      i := -1;
      iCount := ExtractIcon(Hinstance, Pchar(FileName), i);
      ProgressBar.Max := iCount;
      ListView1.Items.BeginUpdate;
      ListView1.Items.Clear;
      Icon := TIcon.Create;
      for i := 0 to iCount -1 do
      begin
        Icon.Handle := ExtractIcon(Hinstance, Pchar(FileName), i);
        ImageList.AddIcon(Icon);
        with ListView1.Items.Add do
        begin
          Caption := ExtractFileName(FileName) + '[' + IntToStr(i + 1) + ']';
          ImageIndex := Items.Count - 1;
        end;
        ProgressBAr.Position := i;
      end;
      ListView1.Items.EndUpdate;
      ProgressBar.Position := 0;
    end;