LPNMTVCUSTOMDRAW pCustomDraw = (LPNMTVCUSTOMDRAW)pNmhdr; switch (pCustomDraw->nmcd.dwDrawStage) { case CDDS_PREPAINT: // Need to process this case and set pResult to CDRF_NOTIFYITEMDRAW, // otherwise parent will never receive CDDS_ITEMPREPAINT notification. (GGH) *pResult = CDRF_NOTIFYITEMDRAW;
// reposuition the viewport so the TreeCtrl DefWindowProc doesn't draw to viewport 0/0 //::SetViewportOrgEx(pCustomDraw->nmcd.hdc, /*m_nOffset*/0, 0, NULL); break;
case CDDS_ITEMPREPAINT: // set the background and foregroundcolor of the item to the background, so you don't see the default drawing of the text //get item state(focus,selected..), because it will be drawn of us nItemState = pCustomDraw->nmcd.uItemState;
pCustomDraw->nmcd.uItemState &= ~CDIS_FOCUS; pCustomDraw->clrText = m_colHilightText; // remember the drawing rectangle of the item so we can draw it ourselves m_pTree->GetItemRect((HTREEITEM) pCustomDraw->nmcd.dwItemSpec, &rcItem, TRUE); *pResult = CDRF_NOTIFYPOSTPAINT; break;
void CLeftView::DrawTreeItem(int nItemState, CRect rcItem, HDC hdc, HTREEITEM hItem) { // if the item has got the focus, we have to draw sorouinding rectangle and fill a rect blue COLORREF colText = m_colText;
if(nItemState & CDIS_FOCUS) { ::FillRect(hdc, &rcItem, (HBRUSH)m_BackBrush.m_hobject); // Add new focus rect code... ::DrawFocusRect( hdc, &rcItem); colText = m_colHilightText; SCOlor">//=:GetSysColor(COLOR_HIGHLIGHTTEXT); } else if(nItemState & CDIS_SELECTED) { ::FillRect(hdc, &rcItem, (HBRUSH)m_GrayBrush.m_hObject); } else { TRACE("CLEAR HIGHn"); // add this to clear leftover highlight bar ::FillRect(hdc, &rcItem, (HBRUSH)m_BackBrushNormal.m_hObject); }
// you may modify them according to your need int nNew = 20; CString strNew = _T(""); strNew.Format(_T("(%d)"),nNew); ::SetTextColor(hdc,RGB(0,0,255)); RECT rc = rcItem; rc.left = rcItem.right+2; rc.right = rc.left + 100; ::FillRect(hdc, &rc, (HBRUSH)m_BackBrushNormal.m_hObject); ::DrawText(hdc,strNew, -1, &rc, DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS); }