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.
    

  • 相关阅读:
    【转】软链接和硬链接到底有啥作用和区别
    useradd命令详解
    【转】Linux下MySQL数据库安装及配置方法
    【转】MySQL的安装与配置——详细教程-window系统下
    mysql服务器常用命令
    【转】DDL/DML/DCL区别概述
    tmux终端工具的简单使用
    linux go环境安装和基本项目结构
    ClickHouse高可用集群的配置
    centos7下使用rpm包安装clickhouse
  • 原文地址:https://www.cnblogs.com/whisht/p/3112679.html
Copyright © 2011-2022 走看看