En la sección Trucos, me topé con este interesante truco para obtener cualquier thumbnail de la Shell, funciona perfecto, pero no logro adaptar un string a PWideChar, como para pasarle los parametros por variables, siempre me tira error, alguna idea?
Código Delphi
[-]
uses ActiveX, ShlObj, ComObj;
type
IExtractImage = interface ['{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}'] function GetLocation(pszPathBuffer: LPWSTR; cchMax: DWORD;
var pdwPriority: DWORD; const prgSize: SIZE; dwRecClrDepth: DWORD;
var pdwFlags: DWORD): HRESULT; stdcall;
function Extract(var phBmpImage: HBITMAP): HRESULT; stdcall;
end;
function GetThumbnail(lpPathName, lpFileName: PWideChar; Width, Height: Integer): TBitmap;
var
Desktop, Folder: IShellFolder;
ItemIDList: PItemIDList;
Flags, Priority: Cardinal;
ExtractImage: IExtractImage;
Res: HRESULT;
hBitmap: Windows.HBITMAP;
Buffer: array[0..MAX_PATH-1] of WideChar;
Size: TSize;
begin
Result := nil;
SHGetDesktopFolder(Desktop);
if LongBool(Desktop.ParseDisplayName(0, nil, lpPathName, PDWORD(0)^, ItemIDList, PDWORD(0)^)) then Exit;
Desktop.BindToObject(ItemIDList, nil, IShellFolder, Folder);
CoTaskMemFree(ItemIDList);
if LongBool(Folder.ParseDisplayName(0, nil, lpFileName, PDWORD(0)^, ItemIDList, PDWORD(0)^)) then Exit;
Folder.GetUIObjectOf(0, 1, ItemIDList, IExtractImage, nil, ExtractImage);
CoTaskMemFree(ItemIDList);
if not Assigned(ExtractImage) then Exit; Size.cx := Width; Size.cy := Height; Priority := 0;
Flags := $28;
Res := ExtractImage.GetLocation(Buffer, SizeOf(Buffer), Priority, Size, 24, Flags);
if (Res = NOERROR) or (Res = E_PENDING) then
begin
if not LongBool(ExtractImage.Extract(hBitmap)) then
begin
Result := TBitmap.Create;
Result.Handle := hBitmap;
end;
end;
end;