ExtractIcon.h
上传用户:hy_wanghao
上传日期:2007-01-08
资源大小:279k
文件大小:2k
源码类别:

Shell编程

开发平台:

Visual C++

  1. #if !defined(AFX_EXTRACTICON_H__20001226_57EC_56A4_0219_0080AD509054__INCLUDED_)
  2. #define AFX_EXTRACTICON_H__20001226_57EC_56A4_0219_0080AD509054__INCLUDED_
  3. #pragma once
  4. //////////////////////////////////////////////////////////////////////////////
  5. // CExtractIcon
  6. template< class T >
  7. class ATL_NO_VTABLE CExtractIcon : 
  8.    public CComObjectRootEx<CComSingleThreadModel>,
  9.    public IExtractIcon
  10. {
  11. public:
  12. DECLARE_NOT_AGGREGATABLE(CExtractIcon)
  13. BEGIN_COM_MAP(CExtractIcon)
  14.    COM_INTERFACE_ENTRY_IID(IID_IExtractIcon,IExtractIcon)
  15. END_COM_MAP()
  16.    CPidl m_pPidl;
  17.    HRESULT _Init(LPCITEMIDLIST pidl)
  18.    {
  19.       m_pPidl.Copy(CPidl::_GetLastItem(pidl));
  20.       return S_OK;
  21.    }
  22.    // IExtractIcon
  23.    STDMETHOD(GetIconLocation)(UINT uFlags, 
  24.                               LPTSTR /*szIconFile*/, 
  25.                               UINT /*cchMax*/, 
  26.                               LPINT piIndex, 
  27.                               LPUINT puFlags)
  28.    {
  29.       ATLASSERT(piIndex);
  30.       ATLASSERT(puFlags);
  31.       if( m_pPidl.IsEmpty() ) return E_FAIL;
  32.       T *pData = reinterpret_cast<T *>((LPITEMIDLIST)m_pPidl);
  33.       if( pData!=NULL ) {
  34.          switch( pData->type ) {
  35.          case PT_FOLDER:
  36.             *piIndex = (uFlags & GIL_OPENICON)==0 ? ICON_INDEX_FOLDER : ICON_INDEX_FOLDER_OPEN;
  37.             *puFlags = GIL_NOTFILENAME;
  38.             break;
  39.          default:
  40.             *piIndex = ICON_INDEX_FILE;
  41.             *puFlags = GIL_NOTFILENAME;
  42.             break;
  43.          }
  44.       }
  45.       return S_OK;
  46.    }
  47.    STDMETHOD(Extract)(LPCTSTR /*pstrName*/, 
  48.                       UINT nIconIndex, 
  49.                       HICON *phiconLarge, 
  50.                       HICON *phiconSmall, 
  51.                       UINT /*nIconSize*/)
  52.    {
  53.       ATLASSERT(phiconLarge);
  54.       ATLASSERT(phiconSmall);
  55.       *phiconLarge = ImageList_GetIcon(_Module.m_ImageLists.m_hImageListLarge, nIconIndex, ILD_TRANSPARENT);
  56.       *phiconSmall = ImageList_GetIcon(_Module.m_ImageLists.m_hImageListSmall, nIconIndex, ILD_TRANSPARENT);
  57.       return S_OK;
  58.    };
  59. };
  60. #endif // !defined(AFX_EXTRACTICON_H__20001226_57EC_56A4_0219_0080AD509054__INCLUDED_)