|
|
|
date: Fri, 6 Jun 2008 13:24:03 -0700,
group: microsoft.public.platformsdk.shell
back
Re: Generating thumbnail of PDF documents using Shell?
function GetFileImage(const Filename: WideString; PreviewSize: Integer):
HBITMAP;
const
IEI_PRIORITY_MAX = $0002;
IEI_PRIORITY_MIN = $0001;
IEI_PRIORITY_NORMAL = $0000;
IEIFLAG_ASYNC = $0001; // ask the extractor if it supports ASYNC
extract (free threaded)
IEIFLAG_CACHE = $0002; // returned from the extractor if it does
NOT cache the thumbnail
IEIFLAG_ASPECT = $0004; // passed to the extractor to beg it to
render to the aspect ratio of the supplied rect
IEIFLAG_OFFLINE = $0008; // if the extractor shouldn't hit the net to
get any content neede for the rendering
IEIFLAG_GLEAM = $0010; // Not supported. --does the image have a
gleam ? this will be returned if it does
IEIFLAG_SCREEN = $0020; // render as if for the screen (this is
exlusive with IEIFLAG_ASPECT )
IEIFLAG_ORIGSIZE = $0040; // render to the approx size passed, but
crop ifneccessary
IEIFLAG_QUALITY = $200; // passed to the Extract method to indicate that
// a slower, higher quality image is desired,
// re-compute the thumbnail
var
FilePath: string;
shellFolder: IShellFolder;
pidl: PItemIDList;
extractImage: IExtractImage;
Buffer: WideString;
Priority: Cardinal;
Flags: Cardinal;
hr: HRESULT;
BmpHandle: HBITMAP;
Size: TSize;
begin
FilePath := IncludeTrailingBackslash(ExtractFilePath(FileName));
shellFolder := GetShellFolder(FilePath);
pidl := ShellFolderParseDisplayName(shellFolder,
ExtractFilename(Filename));
try
//Get the IExtractImage interface of the file
hr := shellFolder.GetUIObjectOf(
0, //Parent window for showing a UI (if Windows needs to)
1, //following pidl contains only one file
pidl, //the file we want the IExtractImage interface for
IID_IExtractImage, //give us back an IExtractImage interface
nil, //Reserved
extractImage);
finally
CoTaskMemFree(pidl);
end;
if (hr <> S_OK) then
begin
//The item doesn't support IExtractImage
Result := 0;
Exit;
end;
//Allocate a string as a dummy buffer
SetLength(Buffer, MAX_PATH);
Size.cx := PreviewSize;
Size.cy := PreviewSize;
Priority := IEI_PRIORITY_NORMAL;
Flags := IEIFLAG_SCREEN or {IEIFLAG_QUALITY or }IEIFLAG_OFFLINE;
hr := extractImage.GetLocation(PWideChar(Buffer), Length(Buffer), Priority,
Size, 32, Flags);
case hr of
S_OK,
Windows.E_PENDING: //E_PENDING means it is pending (and will be done when
we call Extract)
begin
if extractImage.Extract(BmpHandle) = S_OK then
Result := BmpHandle
else
Result := 0;
end;
else
Result := 0;
end;
end;
date: Tue, 29 Jul 2008 14:43:19 -0400
author: Ian Boyd
|
|