문제

I am currently trying to change the background color of a TreeView item. Therefore, I am using this message to create the item:

    SendMessage(ListView, LVM_INSERTITEM, 0, (LPARAM)&lvI);

Additionally, I am handling the custom draw message like this :

        case WM_NOTIFY:
        {
            LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam;
            if (pnm->hdr.code == NM_CUSTOMDRAW)
            {
                LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
                switch (lplvcd->nmcd.dwDrawStage)
                {
                    case CDDS_PREPAINT :
                        return CDRF_NOTIFYITEMDRAW;
                    case CDDS_ITEMPREPAINT:
                        lplvcd->clrTextBk = ???;

                        return CDRF_NEWFONT;
                }
            }

This works fine and I can set the color to whatever I'd like to, However, I have not found a way to pass the color as a parameter right when I send the message, yet. After all, custom draw is useless for me when I can only assign a constant or random color.

Thanks for any kind of help!

도움이 되었습니까?

해결책

When you add the item to the list, you can pass your own data by setting the LVIF_PARAM flag and filling out the lParam member of the LVITEM structure. This then gets passed back to you as NMCUSTOMDRAW::lItemlParam.

Don't get confused by the lParam that that comes with the WM_NOTIFY message itself, that's a different lParam :)

다른 팁

I think the (exact) answer lies here: Using Custom Draw.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top