zoukankan      html  css  js  c++  java
  • Delphi SHMultiFileProperties查看多个文件属性

    library Properties;
    
    { Important note about DLL memory management: ShareMem must be the
      first unit in your library's USES clause AND your project's (select
      Project-View Source) USES clause if your DLL exports any procedures or
      functions that pass strings as parameters or function results. This
      applies to all strings passed to and from your DLL--even those that
      are nested in records and classes. ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL. To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters. }
    
    uses
      Windows,
      Dialogs,
      SysUtils,
      Classes, ActiveX, ShlObj, ComObj;
    {$R *.res}
    
    
    function SHMultiFileProperties(pDataObj: IDataObject; Flag: DWORD): HRESULT;
    stdcall; external 'shell32.dll';
    
    function GetFileListDataObject(Files: TStrings): IDataObject;
    type
      PArrayOfPItemIDList = ^TArrayOfPItemIDList;
      TArrayOfPItemIDList = array[0..0] of PItemIDList;
    var
      Malloc: IMalloc;
      Root: IShellFolder;
      p: PArrayOfPItemIDList;
      chEaten, dwAttributes: ULONG;
      i, FileCount: Integer;
    begin
      Result := nil;
      FileCount := Files.Count;
      if FileCount = 0 then Exit;
      
      OleCheck(SHGetMalloc(Malloc));
      OleCheck(SHGetDesktopFolder(Root));
      p := AllocMem(SizeOf(PItemIDList) * FileCount);
      try
        for i := 0 to FileCount - 1 do
        try
          if not (DirectoryExists(Files[i]) or FileExists(Files[i])) then Continue;
          OleCheck(Root.ParseDisplayName(GetActiveWindow,
                                        nil,
                                        PWideChar(WideString(Files[i])),
                                        chEaten,
                                        p^[i],
                                        dwAttributes));
          except
          end;
        OleCheck(Root.GetUIObjectOf(GetActiveWindow,
                                      FileCount,
                                      p^[0],
                                      IDataObject,
                                      nil,
                                      Pointer(Result)));    
          finally
            for i := 0 to FileCount - 1 do
            begin
              if p^[i] <> nil then Malloc.Free(p^[i]);
            end;
            FreeMem(p);
          end;
        end;
        
    procedure ShowFileProperties(Files: TStrings; aWnd: HWND);
    type
    PArrayOfPItemIDList = ^TArrayOfPItemIDList;
    TArrayOfPItemIDList = array[0..0] of PItemIDList;
    var
    Data: IDataObject;
    begin
      if Files.Count = 0 then Exit;
      Data := GetFileListDataObject(Files);
      SHMultiFileProperties(Data, 0);
    end;
    
    function SplitString(const source, ch: string): TStringList;
    var
      temp, t2: string;
      i: integer;
    begin
      result := TStringList.Create;
      temp := source;
      i := pos(ch, source);
      while i <> 0 do
      begin
        t2 := copy(temp, 0, i - 1);
        if (t2 <> '') then
          result.Add(t2);
        delete(temp, 1, i - 1 + Length(ch));
        i := pos(ch, temp);
      end;
      result.Add(temp);
    end;
    
    procedure ShowProperties(AFiles: PChar); stdcall;
    var
      oList:TStrings;
    begin
      oList:= SplitString(AFiles, ';');
      ShowFileProperties(oList, 0);
    end;
    
    exports
      ShowProperties name 'ShowProperties';
    begin
    end.
    

  • 相关阅读:
    手工杀毒笔记
    中国黑客名单
    SQL Server 2005 数据库知识大全
    sql server和oracle行转列的一种典型方法
    <h1><span>标签在SEO中的作用及用法
    传说能加快vs编译速度(vs2008+cf3.5)
    WPF版调色器
    SQL经典案例
    Silverlight 2 相关文章汇总
    国内一些黑客高手的联系方式
  • 原文地址:https://www.cnblogs.com/whisht/p/3112679.html
Copyright © 2011-2022 走看看