Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CListCtrl: change color of a single row

81 views
Skip to first unread message

Eric Keefer

unread,
Apr 23, 1999, 3:00:00 AM4/23/99
to
I'd like to change maintain black text on most of the rows of my CListCtrl
but would like to have a line or two display in red. Is this possible?

Chip Calvert

unread,
May 5, 1999, 3:00:00 AM5/5/99
to
Eric,

On Fri, 23 Apr 1999 22:33:00 GMT, "Eric Keefer" <kee...@cwix.com>
wrote:

>I'd like to change maintain black text on most of the rows of my CListCtrl
>but would like to have a line or two display in red. Is this possible?

Yes. You will need to handle the NM_CUSTOMDRAW message. Here is an
example:

void CHMListCtrl::OnNotifyCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
//process the new custon draw message
NMCUSTOMDRAW &nmDraw = nmCustomDraw->nmcd;

DWORD DrawStage = nmDraw.dwDrawStage;

switch (DrawStage)
{
case CDDS_PREPAINT:
//activate painting
retval = CDRF_NOTIFYITEMDRAW |
CDRF_NOTIFYPOSTPAINT;
break;
case CDDS_ITEMPREPAINT:
{
if (/* something is true*/)
{
// Set the text color to red
nmCustomDraw->clrText = RGB(255,0,0);
}//if

else if (/* something else is true*/)
{
// Make the font bold
// m_Font is a member of CMyListCtrl
// and is the same as the regular
// font, but bold
HFONT hf = HFONT(m_Font);

HDC dc = nmDraw.hdc;
HGDIOBJ Oldhf= ::SelectObject(dc,hf);

retval |= CDRF_NEWFONT;
}//else if

break;
}//case
}//switch
}//OnNotifyCustomDraw


Posted and emailed.


Chip

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Make it idiot-proof and someone will make a better idiot."
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Remove NO and SPAM from my email address.

0 new messages