You can do it with custom draw if you want to draw the start of the item text with different color than the rest of the item text (or some other variation). Example, to draw the start part of the item in a different color than the rest of item:
1. in CDDS_ITEMPREPAINT set the color for the whole thing and let Windows draw the item.
2. in CDDS_ITEMPOSTPAINT get the DC and select the color you want for the start of the item and use ::DrawText to draw just the start text of the item.
case CDDS_ITEMPREPAINT: {
HTREEITEM hItem = reinterpret_cast<HTREEITEM>(pNMCD->dwItemSpec);
pNMTVCD->clrText = ::GetSysColor(COLOR_GRAYTEXT);
*pResult = CDRF_NOTIFYPOSTPAINT;
}
break;
case CDDS_ITEMPOSTPAINT: {
HTREEITEM hItem = reinterpret_cast<HTREEITEM>(pNMCD->dwItemSpec);
CDC* pDC = CDC::FromHandle(pNMCD->hdc);
const int iDpi = 96;
CRect rcItem;
GetItemRect(
hItem,
rcItem,
TRUE); if (rcItem.IsRectEmpty())
break;
if (myItem) {
CRect rcText(rcItem);
rcText.DeflateRect(
CSize(
::GetSystemMetricsForDpi(SM_CXEDGE, iDpi),
::GetSystemMetricsForDpi(SM_CYEDGE, iDpi)));
CFont *pFont = GetFont();
ASSERT(pFont);
if (pFont) {
const CString sName("my text start");
const int nSavedDC = pDC->SaveDC();
CFont *pFontOld = pDC->SelectObject(pFont);
pDC->SetTextColor(
::GetSysColor(COLOR_WINDOWTEXT));
pDC->DrawText(
sName,
-1,
rcText,
DT_NOPREFIX
| DT_SINGLELINE
| DT_VCENTER);
pDC->SelectObject(pFontOld);
pDC->RestoreDC(nSavedDC);
}
}
break;