Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
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

Re: IShellItemImageFactory high-res icons   
winson.chung wrote:
> 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).

IShellItemImageFactory::GetImage works for me. What kind of files are you trying to get images for? Obviously you can't get jumbo icons for file types that don't support jumbo icons.

-- 
Jim Barry, Microsoft MVP
date: Mon, 23 Jun 2008 16:52:40 +0100   author:   Jim Barry

Re: IShellItemImageFactory high-res icons   
We ended up going the using one of the other low level shell calls to
extract the icon since IShellItemImageFactory wasn't returning the
right ones for system (ie. default zip) icons.

thanks,
 -w

On Jun 23, 11:52 am, "Jim Barry"  wrote:
> winson.chung wrote:
> > 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).
>
> IShellItemImageFactory::GetImage works for me. What kind of files are you trying to get images for? Obviously you can't get jumbo icons for file types that don't support jumbo icons.
>
> --
> Jim Barry, Microsoft MVP
date: Mon, 23 Jun 2008 16:58:03 -0700 (PDT)   author:   winson.chung

Re: IShellItemImageFactory high-res icons   
winson.chung wrote:
> We ended up going the using one of the other low level shell calls to
> extract the icon since IShellItemImageFactory wasn't returning the
> right ones for system (ie. default zip) icons.

Strange...  I just tried it with a zip file and it worked just fine.

-- 
Jim Barry, Microsoft MVP
date: Tue, 24 Jun 2008 11:28:38 +0100   author:   Jim Barry

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us