【问题标题】:WINAPI explorer shell document "details"WINAPI explorer shell 文档“详细信息”
【发布时间】:2013-03-16 01:01:06
【问题描述】:

this question 类似,我正在寻找一种实用的方法来阅读当您在资源管理器中选择“属性”时显示的“详细信息”窗格中的信息。

例如在下面的屏幕截图中,

圈出了一些随机的细节。

我不是在寻找一种方法来确定以其他方式圈出的特定项目(例如,请不要建议如何找出图像的宽度(以像素为单位)),这不是我所追求的。我需要一种方法来解析所有可用信息,以便在我自己的程序中显示,而不必自己“了解”这些文件。这只是为了创建一个特定的用户界面,而不必实际打开显示的对话框。

不管怎样,du jour 语言是 Delphi,但我完全有能力翻译 c++ 或任何其他 winapi 代码方言,但如果你碰巧有 delphi 代码,那对我个人来说将是一个奖励。

编辑:我希望能够获得文档的具体细节,例如 PowerPoint 文档中的幻灯片计数,它不符合您访问大多数文档所具有的属性所需的标准化常量。

例如,我可以使用此代码(但不是幻灯片计数)从 powerpoint 文档中获取一些基本信息。

uses shellapi,ComObj;
{$R *.dfm}

const
  FmtID_SummaryInformation: TGUID =
    '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';

function FileTimeToDateTimeStr(F: TFileTime): string;
var
  LocalFileTime: TFileTime;
  SystemTime: TSystemTime;
  DateTime: TDateTime;
begin
  if Comp(F) = 0 then Result := '-'
  else
  begin
    FileTimeToLocalFileTime(F, LocalFileTime);
    FileTimeToSystemTime(LocalFileTime, SystemTime);
    with SystemTime do
      DateTime := EncodeDate(wYear, wMonth, wDay) +
        EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
    Result := DateTimeToStr(DateTime);
  end;
end;

function GetDocInfo(const FileName: WideString): string;
var
  I: Integer;
  PropSetStg: IPropertySetStorage;
  PropSpec: array[2..19] of TPropSpec;
  PropStg: IPropertyStorage;
  PropVariant: array[2..19] of TPropVariant;
  Rslt: HResult;
  S: string;
  Stg: IStorage;
begin
  Result := '';
  try
    OleCheck(StgOpenStorage(PWideChar(FileName), nil, STGM_READ or
      STGM_SHARE_DENY_WRITE,
      nil, 0, Stg));
    PropSetStg := Stg as IPropertySetStorage;
    OleCheck(PropSetStg.Open(FmtID_SummaryInformation,
      STGM_READ or STGM_SHARE_EXCLUSIVE, PropStg));
    for I := 2 to 19 do
    begin
      PropSpec[I].ulKind := PRSPEC_PROPID;
      PropSpec[I].PropID := I;
    end;
    Rslt := PropStg.ReadMultiple(18, @PropSpec, @PropVariant);
    OleCheck(Rslt);
    if Rslt <> S_FALSE then for I := 2 to 19 do
      begin
        S := '';
        if PropVariant[I].vt = VT_LPSTR then
          if Assigned(PropVariant[I].pszVal) then
            S := PropVariant[I].pszVal;
            case I of
              2:  S  := Format('Title: %s', [S]);
              3:  S  := Format('Subject: %s', [S]);
              4:  S  := Format('Author: %s', [S]);
              5:  S  := Format('Keywords: %s', [S]);
              6:  S  := Format('Comments: %s', [S]);
              7:  S  := Format('Template: %s', [S]);
              8:  S  := Format('Last saved by: %s', [S]);
              9:  S  := Format('Revision number: %s', [S]);
              10: S := Format('Total editing time: %g sec',
                  [Comp(PropVariant[I].filetime) / 1.0E9]);
              11: S := Format('Last printed: %s',
                  [FileTimeToDateTimeStr(PropVariant[I].filetime)]);
              12: S := Format('Create time/date: %s',
                  [FileTimeToDateTimeStr(PropVariant[I].filetime)]);
              13: S := Format('Last saved time/date: %s',
                  [FileTimeToDateTimeStr(PropVariant[I].filetime)]);
              14: S := Format('Number of pages: %d', [PropVariant[I].lVal]);
              15: S := Format('Number of words: %d', [PropVariant[I].lVal]);
              16: S := Format('Number of characters: %d',
                  [PropVariant[I].lVal]);
              17:; // thumbnail
              18: S := Format('Name of creating application: %s', [S]);
              19: S := Format('Security: %.8x', [PropVariant[I].lVal]);
            else
               S := Format('unknown property#%d: %s', [i,S]);

        end;
        if S <> '' then Result := Result + S + #13#10;
      end;
  finally
  end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  memo1.text :=GetDocInfo('C:\mypowerpoint.ppt');
end;

【问题讨论】:

  • @DavidHeffernan 我之前看过这个,并确定如何获得比基本属性更多的东西并不是很明显。我的屏幕截图没有显示的是通常有更多特定于文档类型的部分。例如在 powerpoint 中有许多幻灯片属性。我可以获得所有基本文档属性,如标题、字数、作者等,但没有更具体的属性。
  • 我同意这不是最容易使用的 API,但所有信息都可以通过属性存储获得
  • @DavidHeffernan 感谢您的意见。我已经设法让一些工作现在就足够了,但是它确实在某种程度上依赖于预定义的常量。如果有人有一个简单的解决方案来获取简单的属性列表,包括其人类可读的描述,我将保留这个问题。

标签: windows delphi winapi


【解决方案1】:

Windows 7 SDK 中的 C++ 示例演示了属性枚举(在 Samples\winui\shell\appplatform\PropertyEdit 下),以及CodePlex 上的更长演示。

没有“规范”的属性列表,因为属性系统是可扩展的;但是,Microsoft 属性列表是 SDK 的一部分,可以在 propkey.h 中找到。

【讨论】:

    猜你喜欢
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 2018-06-27
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多