2013-03-26 69 views
3

this question类似,我试图通过一种方式实用地阅读在资源管理器中选择“属性”时显示的“详细信息”窗格中的信息。WINAPI资源管理器外壳文档“详细信息”

例如在下面的屏幕截图,

screenshot

几个随机细节盘旋。

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

对于它的价值,Delphi的语言是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; 
+5

从这里开始:http://msdn.microsoft.com/en-gb/library/windows/desktop/ff728871.aspx – 2013-03-26 09:40:48

+0

@DavidHeffernan我曾经看过,并确定它不是很明显如何获得更多超过基本属性。我的屏幕截图没有显示的是通常有更多的部分是特定于文档类型的。例如在powerpoint中有一些幻灯片属性。我可以得到所有的基本文件属性,如标题,字数,作者等,但任何更具体的不可用。 – unsynchronized 2013-03-26 11:22:51

+1

我同意这不是最简单的API使用,但所有的信息都可以通过属性存储 – 2013-03-26 11:31:15

回答

1

有在C++中的样品在Windows 7 SDK演示属性的枚举(下样品\ winui \壳\ appplatform \ PropertyEdit),以及较长的上CodePlex演示。

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

相关问题