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));

Get selected item in Tree control

Get selected item in Tree control

HTREEITEM hCurrent = m_tree.GetNextItem(TVI_ROOT, TVGN_CARET);
While(hCurrent)
{
//do your code here
hCurrent = m_tree. GetNextItem(hCurrent, TVGN_NEXT);
}

Get selected item in Tree control

Get selected item in Treecontrol


HTREEITEM hCurrent = m_tree.GetNextItem(TVI_ROOT, TVGN_CARET);
CString strName= m_tree.GetItemText(hCurrent);
UINT nData= m_tree.Data(hCurrent);

How to disable tabcontrol?

How to disable tab control?

Draw text over tabcontrol with grey shade…

CDC *pDC;
pDC=this->GetDC();

pDC->SelectObject(GetFont());
pDC->SetBkMode(TRANSPARENT);
if (FALSE==bEnable)
{
pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
rect.top -= ::GetSystemMetrics(SM_CYEDGE);
pDC->DrawText(tcItem.pszText, rect, SINGLELINEDT_VCENTERDT_CENTER);
}
ReleaseDC(pDC);