• 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.
    

  • 相关阅读:
    对协程的一些理解
    JUC中Lock和ReentrantLock介绍及源码解析
    JUC中AQS简介
    Executor框架简介
    CyclicBarrier简介
    CountDownLatch简介
    Semaphore简介
    ThreadPoolExecutor简介
    AtomicInteger简介
    synchronized和volatile简介
  • 原文地址:https://www.cnblogs.com/whisht/p/3112679.html
Copyright © 2020-2023  润新知