win32 ListView CustomDraw ,为什么 dwDrawStage 值总是等于 1

时间:2021-07-05 12:20:20

标签: listview winapi custom-draw

我在做win32 listview控件,想实现CustomDraw,

但是我得到了一些奇怪的东西。 我想知道为什么这个 dwDrawStage 值总是等于 1

$query = "select SUM(send) as SUN from money_transfers where trans_type = 'outbound' UNION select SUM(send) as SUN1 from money_transfers where trans_type = 'inbound'";

OnListViewNotify

bool rst = CreateWinEx(WC_LISTVIEW, NULL,
        WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_EDITLABELS  | LVS_NOCOLUMNHEADER | WS_BORDER,0,
        x,y,w,h,
        hwndParent_, NULL, GetModuleHandle(NULL));

自定义绘图

LRESULT my::listView::OnListViewNotify(HWND hwnd,LPARAM lParam)
{

    NMLISTVIEW* pnmv= (NMLISTVIEW*)lParam;

    LRESULT lResult = 0;

    switch(pnmv->hdr.code)
    {
        case  NM_CUSTOMDRAW:
        {
            idebug("NM_CUSTOMDRAW\n");
            SetWindowLong(hWnd, DWL_MSGRESULT, (LONG)CustomDraw(lParam));
            return TRUE;
        }
        break;
    }
    return(lResult);
}

想实现CustomDraw,但我得到了一些奇怪的东西。 我想知道为什么这个 dwDrawStage 值总是等于 1

调试信息

LRESULT  my::listView::CustomDraw( LPARAM lParam )
{
    //NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
    LPNMLVCUSTOMDRAW pLVCD = (LPNMLVCUSTOMDRAW) lParam;
    
    idebug("dwDrawStage:%d\n",pLVCD->nmcd.dwDrawStage);

     switch(pLVCD->nmcd.dwDrawStage) 
    {
        case CDDS_PREPAINT:
        {
            //request notifications for individual listview items
            return CDRF_NOTIFYITEMDRAW;
        }    
        case CDDS_ITEMPREPAINT: //Before an item is drawn
        {
            return CDRF_NOTIFYSUBITEMDRAW;
        }
        case CDDS_SUBITEM | CDDS_ITEMPREPAINT: //Before a subitem is drawn
        {
            switch(pLVCD->iSubItem)
            {
                case 0:
                {
                    pLVCD->clrText   = RGB(255,255,255);
                    pLVCD->clrTextBk = RGB(240,55,23);
                    return CDRF_NEWFONT;

                }
                case 1:
                {
                    pLVCD->clrText   = RGB(255,255,0);
                    pLVCD->clrTextBk = RGB(0,0,0);
                    return CDRF_NEWFONT;
                }
            }
        }
    }
    return CDRF_DODEFAULT;
}

感谢您分享智慧和经验;

1 个答案:

答案 0 :(得分:0)

关键在于@Adrian Mole 所说的返回值。

当我返回 CDRF_NEWFONT 或返回 CDRF_NOTIFYITEMDRAW 时,问题消失了。