gpt4 book ai didi

C++ winapi ListView NM_CUSTOMDRAW : not getting CDDS_ITEMPREPAINT

转载 作者:行者123 更新时间:2023-11-30 05:20:42 29 4
gpt4 key购买 nike

我正在尝试更改我从资源创建的 ListView 的行文本颜色。为此,我在对话过程中处理 NM_CUSTOMDRAW。如果重要的话,这是一个模态对话框。根据the documentation , dwDrawStage 在返回 CDRF_NOTIFYITEMDRAW 后应该等于 CDDS_ITEMPREPAINT。但这种情况并非如此。我收到每件商品的 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

最佳答案

我发现了问题: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;

关于C++ winapi ListView NM_CUSTOMDRAW : not getting CDDS_ITEMPREPAINT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40549962/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com