// Written by Dan Clark :: February 15, 2002
/* In your MessageMap in your .h add: afx_msg void OnCustomdrawList(NMHDR*, LRESULT*);
//}}AFX_VIRTUAL In your MessageMap in your .cpp add: ON_NOTIFY(NM_CUSTOMDRAW, MY_CTRL_ID, OnCustomdrawList) */ // Your Mainframe function : void YourMainFrame::OnCustomdrawList ( NMHDR* pNMHDR, LRESULT* pResult ) { NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR ); // Take the default processing unless we set this to something else below. *pResult = 0; // First thing - check the draw stage. If it's the control's prepaint // stage, then tell Windows we want messages for every item. if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage ) { *pResult = CDRF_NOTIFYITEMDRAW; } else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage ) { // This is the notification message for an item. We'll request // notifications before each subitem's prepaint stage. *pResult = CDRF_NOTIFYSUBITEMDRAW; } else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage ) { // This is the prepaint stage for a subitem. Here's where we set the // item's text and background colors. Our return value will tell // Windows to draw the subitem itself, but it will use the new colors // we set here. // The text color will be GREY if DoesFontMapExist() is true, otherwise Black COLORREF crText; if (2 == pLVCD->iSubItem ) { // Make the font bold // m_Font is a member of CMyListCtrl // and is the same as the regular // font, but bold HFONT hf = (HFONT)bold_font; HDC dc = pLVCD->nmcd.hdc; orig_font =(CFont *) ::SelectObject(dc,hf); *pResult |= CDRF_NEWFONT; if (DoesFontMapExist(pLVCD->nmcd.dwItemSpec)) crText = RGB(132,130,132); else crText = RGB(0,0,0); pLVCD->clrText = crText; } else { // Restore the original font HFONT hf = HFONT(orig_font); HDC dc = pLVCD->nmcd.hdc; HGDIOBJ Oldhf= ::SelectObject(dc,hf); *pResult |= CDRF_NEWFONT; crText = RGB(0,0,0); pLVCD->clrText = crText; // pLVCD->nmcd.hdc //crBkgnd = } // Make background red :-D COLORREF crBkgnd = RGB(255,0,0); // Store the colors back in the NMLVCUSTOMDRAW struct. pLVCD->clrTextBk = crBkgnd; // Tell Windows to paint the control itself. *pResult = CDRF_DODEFAULT; } }