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



我正在开发win32列表视图控件,想要实现CustomDraw、

但我有点奇怪我想知道为什么这个dwDrawStage值总是等于1

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

OnListViewNotify

LRESULT my::listView::OnListViewNotify(HWND hwnd,LPARAM lParam)
{
NMLISTVIEW* pnmv= (NMLISTVIEW*)lParam;
LRESULT lResult = 0;
switch(pnmv->hdr.code)
{
case  NM_CUSTOMDRAW:
{
idebug("NM_CUSTOMDRAWn");
SetWindowLong(hWnd, DWL_MSGRESULT, (LONG)CustomDraw(lParam));
return TRUE;
}
break;
}
return(lResult);
}

CustomDraw

LRESULT  my::listView::CustomDraw( LPARAM lParam )
{
//NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
LPNMLVCUSTOMDRAW pLVCD = (LPNMLVCUSTOMDRAW) lParam;

idebug("dwDrawStage:%dn",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;
}

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

来自调试的信息

hdr.code->NM_CUSTOMDRAW
dwDrawStage:1

感谢您分享您的智慧和经验;

正如@Adrian Mole所说,关键是关于返回值。

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

相关内容

  • 没有找到相关文章

最新更新