简体   繁体   English

颜色特定 treeview 项目使用 WIN32 API (C/C++)

[英]Color specific treeview item using WIN32 API (C/C++)

I wanted to create a tree view where specific items have a different back & text colors.我想创建一个树视图,其中特定项目具有不同的背面和文本 colors。 I did found the following solution in the internet: Win32 Custom Draw Treeview Control , but here they color each item according to its level.我确实在互联网上找到了以下解决方案: Win32 Custom Draw Treeview Control ,但这里他们根据每个项目的级别为每个项目着色。 This is close to what I want, but I want to color just a specific treeview item regardless of its level, lets say by its TVITEM handle or its HTREEITEM.这与我想要的很接近,但我只想为特定的 treeview 项目着色,而不管其级别如何,比如说它的 TVITEM 句柄或它的 HTREEITEM。

Is it possible to do such a thing using the NM_CUSTOMDRAW message?是否可以使用NM_CUSTOMDRAW消息来做这样的事情? If not, how can I do such a thing?如果没有,我怎么能做这样的事情?

Edit: I've been trying to use the item's lParam in order to identify the treeview item, but the items remain invisible for some reason.编辑:我一直在尝试使用该项目的lParam来识别 treeview 项目,但由于某种原因这些项目仍然不可见。 Here is my function which is supposed to handle the custom draw:这是我的 function 应该处理自定义绘图:

/*
This function will custom draw a tree view
Input: (LRESULT*) res = To store the result (by reference, to be stored)
       (HWND) window = The handled window
       (LPNMTVCUSTOMDRAW) item = The item to draw
       (TVITEM) tvItem = The tv item that should be custom drawn
Output: (BOOL) TRUE if should use the stored value, otherwise FALSE
*/
BOOL customDrawTreeView(LRESULT* res, HWND window, LPNMTVCUSTOMDRAW item, TVITEM tvItem)
{
    switch (item->nmcd.dwDrawStage)
    {
    case CDDS_PREPAINT:
        *res = CDRF_NOTIFYITEMDRAW;
        return TRUE;
        break;
    case CDDS_ITEMPREPAINT:
        if (tvItem.lParam == item->nmcd.lItemlParam)
        {
            item->clrTextBk = 0x383838;
            item->clrText = RGB(255, 255, 255);
            *res = CDRF_SKIPDEFAULT;
            return TRUE;
        }

        break;
    }

    return FALSE;
}

Yes.是的。 You can attach information to the tree item using the TVITEM::lParam member.您可以使用TVITEM::lParam成员将信息附加到树项。 This value is sent with the NM_CUSTOMDRAW message in the nmcd.lItemlParam member of the NMTVCUSTOMDRAW struct.该值与NMTVCUSTOMDRAW结构的nmcd.lItemlParam成员中的NM_CUSTOMDRAW消息一起发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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