Color CListCtrl column Background without the CDDS_ITEMPREPAINT phase

418 views Asked by At

I Want to paint the Background of the first column grey. The problem with CDDS_ITEMPREPAINT is, that it only colors the background if there is an item. Just like this:

enter image description here

At the moment, this is my code:

{
LPNMLVCUSTOMDRAW pNMLVCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
    *pResult = CDRF_DODEFAULT;
    switch (pNMLVCD->nmcd.dwDrawStage)
    {
    case CDDS_PREPAINT:
        *pResult = CDRF_NOTIFYITEMDRAW;
        break;

    case CDDS_ITEMPREPAINT:
        *pResult = CDRF_NOTIFYSUBITEMDRAW;
        break;

    case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
        if (pNMLVCD->iSubItem == 0)
        {
            pNMLVCD->clrTextBk = RGB(97,97,97);
        }
        else
        {
            pNMLVCD->clrTextBk = RGB(255,255,255);
        }
        break;
    }
}

Can anyone explain me how to solve this?

1

There are 1 answers

0
xMRi On

There is no way to accomplish this with custom draw.

Even with ownerdraw the routines are only called for exisitng items. To color the free area you may need to overwrite WM_ERASEBKGND and you Need to do your own stuff there.