15,979
社区成员
发帖
与我相关
我的任务
分享
void CMyTree::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
LPNMTVCUSTOMDRAW lpnmcd = (LPNMTVCUSTOMDRAW) pNMCD;
if (lpnmcd ->nmcd.dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
}
else if (lpnmcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
HTREEITEM hItem=(HTREEITEM) lpnmcd->nmcd.dwItemSpec;
HDC hdc = pNMCD->hdc;
UINT state = GetItemState(hItem,TVIF_STATE);
CRect rcItem(pNMCD->rc);
int ind=GetIndent();// =20
rcItem.left += ind*lpnmcd->iLevel;
rcItem.right += ind*lpnmcd->iLevel;
//draw bt box
CRect rc;// h=20
rc=rcItem;
// rc.left +=2;
rc.right =rc.left+16;
rc.top +=2;
rc.bottom-=2;
if(state & TVIS_EXPANDED)
DrawIconEx(hdc,rc.left,rc.top,m_hIcon2,16,16,NULL,(HBRUSH)NULL, DI_NORMAL);
else
DrawIconEx(hdc,rc.left,rc.top,m_hIcon1,16,16,NULL,(HBRUSH)NULL, DI_NORMAL);
//draw image
int nImage,nSelectedImage;
GetItemImage(hItem, nImage, nSelectedImage);
//
rc=rcItem;
rc.left +=26;
rc.right =rc.left+16;
rc.top +=2;
rc.bottom-=2;
HICON ico;
if (state & TVIS_SELECTED)
{
::SetBkColor(hdc,RGB(255,0,0));
ico=((CTreeCtrlDlg*)GetParent())->ImageTreeList.ExtractIcon(nSelectedImage);
}
else
{
::SetBkColor(hdc,RGB(255,255,255));
ico=((CTreeCtrlDlg*)GetParent())->ImageTreeList.ExtractIcon(nImage);
}
//
DrawIconEx(hdc,rc.left,rc.top,ico,16,16,NULL,(HBRUSH)NULL, DI_NORMAL);
//
CString strText;
strText=GetItemText(hItem);
//
rcItem.left += 50;//| DT_SINGLELINE| DT_VCENTER| DT_SINGLELINE | DT_VCENTER
DrawText(hdc,strText, strText.GetLength(), &rcItem, DT_LEFT);
rcItem.top+=20;
DrawText(hdc,"2nd Line", 8, &rcItem, DT_LEFT);
*pResult = CDRF_SKIPDEFAULT;
return;
}
//
*pResult = CDRF_DODEFAULT;
return;
}