简体   繁体   中英

Winapi : Change Color of a TreeView using CustomDraw

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 :)

我认为(确切的)答案就在这里: 使用Custom Draw

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM