Unable to color sub items in a CListCtrl

I am changing the colors of separate lines of a CListCtrl using OnCustomDraw, but it cannot change the text color of sub items (only the background is changed). Can someone tell me what I should change to solve this problem - is it possible from whithin OnCustomDraw?. The code of the OnCustomDraw I am using is as follows:


void CMyListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
      LPNMLVCUSTOMDRAW lvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
      switch(lvcd->nmcd.dwDrawStage)
      {
            case CDDS_PREPAINT:
                  *pResult = CDRF_NOTIFYSUBITEMDRAW;
                  break;
            case CDDS_ITEMPREPAINT:
                  *pResult = CDRF_NOTIFYSUBITEMDRAW;
                  break;
            case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
            {
                  *pResult = CDRF_DODEFAULT;
                  int iCol = lvcd->iSubItem;
                  int iRow = lvcd->nmcd.dwItemSpec;

                  COLORREF c = RGB(240, 240, 255);
                  CBrush brush(c);
                  CRect rc;
                  GetCellRect(iRow, iCol, LVIR_BOUNDS, rc);
                  // get the device context.
                  CDC *pDC= CDC::FromHandle(lvcd->nmcd.hdc);
                  pDC->FillRect (rc, &brush);
                  lvcd->clrTextBk = c;
                  lvcd->clrText = ::GetSysColor(COLOR_HIGHLIGHT);
                  *pResult = CDRF_NEWFONT;

                  break;
            }
            default:
                  *pResult = CDRF_DODEFAULT;
      }
}

Brian_HPAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

V_BapatCommented:
Remove these lines:

COLORREF c = RGB(240, 240, 255);
CBrush brush(c);
CRect rc;
GetCellRect(iRow, iCol, LVIR_BOUNDS, rc);
// get the device context.
CDC *pDC= CDC::FromHandle(lvcd->nmcd.hdc);
pDC->FillRect (rc, &brush);


Just put:

lvcd->clrTextBk = RGB(240, 240, 255);
lvcd->clrText = ::GetSysColor(COLOR_HIGHLIGHT);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
V_BapatCommented:
Also try this:

lvcd->clrText = RGB(255, 0, 0);

Vicky
0
Brian_HPAuthor Commented:
First, the delete lines proposed are need, otherwise white areas can appear! Therefore, I could not delete that.

The proposed answer did not help, but the comment helped: The actual problem was the ::GetSysColor because COLOR_HIGHLIGT is different for subitems than for the main item.
0
V_BapatCommented:
>First, the delete lines proposed are need, otherwise white areas can appear!

I did not get you. Can you please tell me what is the purpose of that? And what do you mean by 'white areas can appear'?

Vicky
0
Brian_HPAuthor Commented:
Ok.

Assume an item of the CListCtrl is selected, then it gets colored by the above. The CListCtrl looses the focus and afterwards it is repainted for some reason, the above coloring is still present but a white area (rectangle) appears between the end of the text of the main item and the sub item, eg.
  ["MAIN ITEM"xxxxxxxxxx"SUB ITEM"]
The x'ed area is white and the "..." areas are in 'my' color.

Was this more clear ?

Brian
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.