與this question類似,我試圖通過一種方式實用地閱讀在資源管理器中選擇「屬性」時顯示的「詳細信息」窗格中的信息。WINAPI資源管理器外殼文檔「詳細信息」
例如在下面的屏幕截圖,
幾個隨機細節盤旋。
我不是以某種方式確定以某種其他方式盤旋的具體項目(例如,請不要建議如何找出圖像的像素寬度),這不是我所追求的。我需要一種方法來解析所有可用的信息,以便在我自己的程序中進行顯示,而無需親自「知道」這些文件。這只是創建一個特定的用戶界面,而不必實際打開顯示的對話框。
對於它的價值,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;
從這裏開始:http://msdn.microsoft.com/en-gb/library/windows/desktop/ff728871.aspx – 2013-03-26 09:40:48
@DavidHeffernan我曾經看過,並確定它不是很明顯如何獲得更多超過基本屬性。我的屏幕截圖沒有顯示的是通常有更多的部分是特定於文檔類型的。例如在powerpoint中有一些幻燈片屬性。我可以得到所有的基本文件屬性,如標題,字數,作者等,但任何更具體的不可用。 – unsynchronized 2013-03-26 11:22:51
我同意這不是最簡單的API使用,但所有的信息都可以通過屬性存儲 – 2013-03-26 11:31:15