How to change highlight color in list control in mfc

how to change highlight color in list management in mfc. I did not find any api in clistctrl. I redefine NM_CUSTOMDRAW as descripbed in msdn but when I click on any item in the list it shows half blue and half black why does blue go?

+3
source share
2 answers

You need to override the NM_CUSTOMDRAW handler . Check out this example .

+4
source

I managed to change the color of the selected element based on the answer of Cyril V. Lyadvinsky.

CTreeCtrl, IDC_TEST_DEF_TREE.
OnNMCustomdraw . :

ON_NOTIFY(NM_CUSTOMDRAW, IDC_TEST_DEF_TREE, OnNMCustomdraw)

:

void CSelectTestDefinitionDlg::OnNMCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
    LPNMLVCUSTOMDRAW lpLVCustomDraw = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
    switch (lpLVCustomDraw->nmcd.dwDrawStage)
    {
    case CDDS_ITEMPREPAINT:
    case CDDS_SUBITEM:
        if (lpLVCustomDraw->nmcd.uItemState & CDIS_SELECTED)
        {
            // Your color definitions here:
            lpLVCustomDraw->clrText = RGB(255, 255, 255);
            lpLVCustomDraw->clrTextBk = RGB(0, 70, 60);
        }
        break;

    default:
        break;
    }

    *pResult = 0;
    *pResult |= CDRF_NOTIFYPOSTPAINT;
    *pResult |= CDRF_NOTIFYITEMDRAW;
    *pResult |= CDRF_NOTIFYSUBITEMDRAW;
}
0

Source: https://habr.com/ru/post/1763023/


All Articles