c ++ winapi listview NM_CUSTOMDRAW:没有得到CDDS_ITEMPREPAINT

时间:2016-11-11 14:21:37

标签: c++ windows listview winapi

我正在尝试更改我从资源制作的列表视图的行文本颜色。为此,我在对话过程中处理NM_CUSTOMDRAW。这是一个模态对话框,如果重要的话。根据{{​​3}},  返回dwDrawStage后,CDDS_ITEMPREPAINT应该等于CDRF_NOTIFYITEMDRAW。但这种情况并非如此。我收到CDDS_PREPAINT的每件商品。

我做错了什么?

这就是我回复邮件的方式:

        case WM_NOTIFY:

        if (((LPNMHDR)lParam)->hwndFrom == GetDlgItem(hwnd, IDC_List2) && ((LPNMHDR)lParam)->code == NM_CUSTOMDRAW) 
        {
            int result = CDRF_DODEFAULT;
            LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;
            switch (lplvcd->nmcd.dwDrawStage) 
            {
                case CDDS_PREPAINT:
                    result = CDRF_NOTIFYITEMDRAW;
                    break;
                case CDDS_ITEMPREPAINT: //never gets executed
                    lplvcd->clrText = RGB(255, 0, 0);
                    result = CDRF_NEWFONT;
                    break;
            }

            //SetWindowLongPtr(hEdit, DWLP_MSGRESULT, result);
            //return TRUE;
            return result;
        }
        break;

这些是ListView的属性:

IDC_List2,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_NOLABELWRAP | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,205,18,363,197,WS_EX_CLIENTEDGE

1 个答案:

答案 0 :(得分:1)

我发现了问题: WM_NOTIFY在对话框中处理,因此我必须return the values accordingly。问题是,我在窗口中使用了错误的变量(在这种情况下为hEdit)。

如果有人关心,这是更正后的版本:

case WM_NOTIFY:

        if (((LPNMHDR)lParam)->hwndFrom == GetDlgItem(hwnd, IDC_List2) && ((LPNMHDR)lParam)->code == NM_CUSTOMDRAW) 
        {
            int result = CDRF_DODEFAULT;
            LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;
            switch (lplvcd->nmcd.dwDrawStage) 
            {
                case CDDS_PREPAINT:
                    result = CDRF_NOTIFYITEMDRAW;
                    break;
                case CDDS_ITEMPREPAINT:
                    lplvcd->clrText = RGB(255, 0, 0);
                    result = CDRF_NEWFONT;
                    break;
            }
            SetWindowLongPtr(hDialog, DWLP_MSGRESULT, result);
            return TRUE;
        }
        break;