求助,listview控件NM_CUSTOMDRAW中的CDDS_ITEMPREPAINT不响应

marshallshenzhe 2011-09-27 05:27:04
代码如下:

INT_PTR CBatRegDlg::DialogProc( HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_NOTIFY:
{
LPNMHDR nmh = (LPNMHDR) lParam;
if(m_list == GetDlgItem(hDlg ,nmh->idFrom) && nmh->code == NM_CUSTOMDRAW)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( lParam);
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
return CDRF_NOTIFYITEMDRAW;//这里可以进来
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{

COLORREF rText; //这里从不进来
crText = RGB(255,0,0);
pLVCD->clrText = crText;


return CDRF_DODEFAULT;
}
return CDRF_DODEFAULT;
}
}
}
}

哪位高手能指点哈,先谢谢啦!!
...全文
310 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
shaitliftworld 2011-10-10
我也碰到这个问题呀.
  • 打赏
  • 举报
回复
schlafenhamster 2011-09-27
case WM_NOTIFY:
if(wParam==IDC_LISTVIEW)
{
return (ListViewCustomDraw(m_hListView, lParam));
}
//
//////////////////////////////////////////////////////////////
LRESULT ListViewCustomDraw(HWND hwnd, LPARAM lParam){
LPNMHDR pnmh = (LPNMHDR) lParam;

if (pnmh->code != NM_CUSTOMDRAW) return 0;

LPNMLVCUSTOMDRAW lpNMCustomDraw = (LPNMLVCUSTOMDRAW) lParam;

int nResult = CDRF_DODEFAULT;

if (CDDS_PREPAINT == lpNMCustomDraw->nmcd.dwDrawStage)
{
nResult = CDRF_NOTIFYITEMDRAW;
}
else if (CDDS_ITEMPREPAINT == lpNMCustomDraw->nmcd.dwDrawStage)
{
nResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == lpNMCustomDraw->nmcd.dwDrawStage)
{
nResult = CDRF_SKIPDEFAULT;

const DWORD dwStyle = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS;

HDC hdc = lpNMCustomDraw->nmcd.hdc;
SetBkMode(hdc,TRANSPARENT);
int nItem = (int)lpNMCustomDraw->nmcd.dwItemSpec;
int nSubItem = lpNMCustomDraw->iSubItem;

BOOL bItemSelected = ListView_GetItemState(hwnd, nItem, LVIS_SELECTED);

RECT subItemRect;
ListView_GetSubItemRect(hwnd, nItem, nSubItem, LVIR_BOUNDS, &subItemRect);
//
HBRUSH brsh=0;
if (bItemSelected)
{ //OutputDebugString("bItemSelected\n");
brsh=CreateSolidBrush(RGB(255, 128, 128));
FillRect(hdc, &subItemRect,brsh);
}
else
{// not Selected
brsh=CreateSolidBrush(RGB(51+nItem*30, 153, 255-nItem*30));
FillRect(hdc, &subItemRect,brsh);
}
if(brsh) DeleteObject(brsh);
//
if(nSubItem==0)
{//OutputDebugString("bmp\n");
RECT iconRect;
ListView_GetSubItemRect(hwnd, nItem, nSubItem, LVIR_ICON, &iconRect);
OffsetRect(&iconRect, -1, 0);
HBITMAP oldbmp=(HBITMAP)SelectObject(g_hMemDC,g_hbmNormal);
BitBlt(hdc,iconRect.left, iconRect.top, 16, 16,g_hMemDC,0,0,SRCCOPY);
SelectObject(hdc,oldbmp);
}
//
TCHAR szText[260];
ListView_GetItemText(hwnd, nItem, nSubItem, szText, 260);
OffsetRect(&subItemRect, 18, 0);
DrawText(hdc, szText, strlen(szText), &subItemRect, dwStyle);
}
return nResult;
}
  • 打赏
  • 举报
回复
marshallshenzhe 2011-09-27
自己顶下
  • 打赏
  • 举报
回复
发帖
界面

1.5w+

社区成员

VC/MFC 界面
社区管理员
  • 界面
加入社区
帖子事件
创建了帖子
2011-09-27 05:27
社区公告
暂无公告