|
|
|
date: Fri, 20 Jun 2008 08:10:38 -0700 (PDT),
group: microsoft.public.platformsdk.shell
back
IShellItemImageFactory high-res icons
Hi all,
I'm trying to get high-resolution icons for a list of files that we
are displaying, but it doesn't seem to be working (code below). I'm
getting low-res icons drawn inside a bitmap of the dimensions
specified (ie. there would be a 48x48 icon in the center of the
256x256 icon returned from IShellItemImageFactory::GetImage()), and
SIIGBF_RESIZETOFIT does not seem to do anything (not sure why it's not
in the docs any more).
Any ideas on how we can pull the images, like from this example here?
http://mattolenik.spaces.live.com/default.aspx?mkt=en-US&partner=Live.Spaces?71e14708
Thanks,
w
CODE:
GUID shellItemID = {0x7e9fb0d3, 0x919f, 0x4307, {0xab, 0x2e, 0x9b,
0x18, 0x60, 0x31, 0x0c, 0x93}};
IShellItem2 * psi = NULL;
IShellItemImageFactory * psiif = NULL;
HICON icon = NULL;
HRESULT (WINAPI* pfnSHCreateItemFromParsingName)(PCWSTR, IBindCtx *,
REFIID, void **) = NULL;
HMODULE hLib = GetModuleHandle("shell32");
if (hLib)
{
// Attempt to get the address of SHCreateItemFromParsingName
(FARPROC&) pfnSHCreateItemFromParsingName =
GetProcAddress(hLib, "SHCreateItemFromParsingName");
if (pfnSHCreateItemFromParsingName)
{
// Create an IShellItem from the supplied source path
IShellItem * psiIcon = NULL;
HRESULT hr;
hr =
pfnSHCreateItemFromParsingName(T2CW(FilePath.c_str()), NULL,
shellItemID, (void **) &psi);
if (SUCCEEDED(hr))
{
HBITMAP iconBitmap = NULL;
SIZE iconSize;
iconSize.cx = 256;
iconSize.cy = 256;
IShellItemImageFactory * psiif = NULL;
psi->QueryInterface(IID_IShellItemImageFactory, (void **) &psiif);
hr = psiif->GetImage(iconSize, SIIGBF_RESIZETOFIT |
SIIGBF_BIGGERSIZEOK | SIIGBF_ICONONLY, &iconBitmap);
if (SUCCEEDED(hr))
{
// we've got the bitmap icon, so convert it into
an hicon
BITMAP iconBitmapInfo;
GetObject(iconBitmap, sizeof(BITMAP),
(LPSTR) &iconBitmapInfo);
HBITMAP iconBitmapMask
= ::CreateCompatibleBitmap(::GetDC(NULL), iconBitmapInfo.bmWidth,
iconBitmapInfo.bmHeight);
ICONINFO iconInfo = {0};
iconInfo.fIcon = TRUE;
iconInfo.hbmColor = iconBitmap;
iconInfo.hbmMask = iconBitmapMask;
icon = ::CreateIconIndirect(&iconInfo);
::DeleteObject(iconBitmapMask);
psiif->Release();
psi->Release();
return icon;
}
psi->Release();
}
}
}
date: Fri, 20 Jun 2008 08:10:38 -0700 (PDT)
author: winson.chung
|
|