Thursday, April 10, 2008

Getting icon associated with a File

Getting icon associated with a File !!



HICON hSmallIcon = NULL;
HICON hBigIcon = NULL;
CComPtr DesktopPtr;
CComPtr psfDrives;
LPITEMIDLIST DrivePidl = NULL;
HRESULT hr = SHGetDesktopFolder(&DesktopPtr);

BSTR bstr = strFilename.AllocSysString();
hr = DesktopPtr->ParseDisplayName(NULL, NULL,(LPOLESTR)bstr,NULL, &DrivePidl, NULL);
::SysFreeString(bstr);
LPCITEMIDLIST pidlRelative = NULL;
hr = SHBindToParent (DrivePidl, IID_IShellFolder, (LPVOID*)&psfDrives, &pidlRelative);
CComPtr DiskIcon;
hr = psfDrives->GetUIObjectOf(NULL, 1, &pidlRelative,
IID_IExtractIcon, NULL, (LPVOID*)&DiskIcon);

DiskIcon->GetIconLocation(0,szFileName,MAX_PATH,&IconIndex,&uFlags);
DiskIcon->Extract(szFileName,IconIndex,&hBigIcon,&hSmallIcon,MAKELONG(16,16));

No comments:

Post a Comment