ExtractIcon.h
上传用户:hy_wanghao
上传日期:2007-01-08
资源大小:279k
文件大小:2k
- #if !defined(AFX_EXTRACTICON_H__20001226_57EC_56A4_0219_0080AD509054__INCLUDED_)
- #define AFX_EXTRACTICON_H__20001226_57EC_56A4_0219_0080AD509054__INCLUDED_
- #pragma once
- //////////////////////////////////////////////////////////////////////////////
- // CExtractIcon
- template< class T >
- class ATL_NO_VTABLE CExtractIcon :
- public CComObjectRootEx<CComSingleThreadModel>,
- public IExtractIcon
- {
- public:
- DECLARE_NOT_AGGREGATABLE(CExtractIcon)
- BEGIN_COM_MAP(CExtractIcon)
- COM_INTERFACE_ENTRY_IID(IID_IExtractIcon,IExtractIcon)
- END_COM_MAP()
- CPidl m_pPidl;
- HRESULT _Init(LPCITEMIDLIST pidl)
- {
- m_pPidl.Copy(CPidl::_GetLastItem(pidl));
- return S_OK;
- }
- // IExtractIcon
- STDMETHOD(GetIconLocation)(UINT uFlags,
- LPTSTR /*szIconFile*/,
- UINT /*cchMax*/,
- LPINT piIndex,
- LPUINT puFlags)
- {
- ATLASSERT(piIndex);
- ATLASSERT(puFlags);
- if( m_pPidl.IsEmpty() ) return E_FAIL;
- T *pData = reinterpret_cast<T *>((LPITEMIDLIST)m_pPidl);
- if( pData!=NULL ) {
- switch( pData->type ) {
- case PT_FOLDER:
- *piIndex = (uFlags & GIL_OPENICON)==0 ? ICON_INDEX_FOLDER : ICON_INDEX_FOLDER_OPEN;
- *puFlags = GIL_NOTFILENAME;
- break;
- default:
- *piIndex = ICON_INDEX_FILE;
- *puFlags = GIL_NOTFILENAME;
- break;
- }
- }
- return S_OK;
- }
- STDMETHOD(Extract)(LPCTSTR /*pstrName*/,
- UINT nIconIndex,
- HICON *phiconLarge,
- HICON *phiconSmall,
- UINT /*nIconSize*/)
- {
- ATLASSERT(phiconLarge);
- ATLASSERT(phiconSmall);
- *phiconLarge = ImageList_GetIcon(_Module.m_ImageLists.m_hImageListLarge, nIconIndex, ILD_TRANSPARENT);
- *phiconSmall = ImageList_GetIcon(_Module.m_ImageLists.m_hImageListSmall, nIconIndex, ILD_TRANSPARENT);
- return S_OK;
- };
- };
- #endif // !defined(AFX_EXTRACTICON_H__20001226_57EC_56A4_0219_0080AD509054__INCLUDED_)