win32 ListView Custom Draw,为什么dwDrawStage值总是等于1
win32 ListView CustomDraw , why dwDrawStage value is alway equal to 1
我正在做win32 listview控件,想实现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_CUSTOMDRAW\n");
SetWindowLong(hWnd, DWL_MSGRESULT, (LONG)CustomDraw(lParam));
return TRUE;
}
break;
}
return(lResult);
}
自定义绘图
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;
}
想实现CustomDraw,但是我遇到了一些奇怪的事情。
我想知道为什么这个 dwDrawStage 值总是等于 1
来自调试的信息
hdr.code->NM_CUSTOMDRAW
dwDrawStage:1
感谢您分享您的智慧和经验;
正如@Adrian Mole 所说,关键是关于 return 值。
当我 return CDRF_NEWFONT 或 return CDRF_NOTIFYITEMDRAW 时问题消失了。
我正在做win32 listview控件,想实现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_CUSTOMDRAW\n");
SetWindowLong(hWnd, DWL_MSGRESULT, (LONG)CustomDraw(lParam));
return TRUE;
}
break;
}
return(lResult);
}
自定义绘图
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;
}
想实现CustomDraw,但是我遇到了一些奇怪的事情。 我想知道为什么这个 dwDrawStage 值总是等于 1
来自调试的信息
hdr.code->NM_CUSTOMDRAW
dwDrawStage:1
感谢您分享您的智慧和经验;
正如@Adrian Mole 所说,关键是关于 return 值。
当我 return CDRF_NEWFONT 或 return CDRF_NOTIFYITEMDRAW 时问题消失了。