|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
LRESULT ListViewCustomDraw(HWND hwnd, NMLVCUSTOMDRAW* pcd)
{
int nResult = CDRF_DODEFAULT;
if (CDDS_PREPAINT == pcd->nmcd.dwDrawStage)
{
return CDRF_DODEFAULT | CDRF_NOTIFYSUBITEMDRAW;
}
else if (CDDS_ITEMPREPAINT == pcd->nmcd.dwDrawStage)
{
return nResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pcd->nmcd.dwDrawStage)
{
nResult = CDRF_SKIPDEFAULT;
const DWORD dwStyle = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS;
HDC hdc = pcd->nmcd.hdc;
SetBkMode(hdc,TRANSPARENT);
int nItem = pcd->nmcd.dwItemSpec;
int nSubItem = pcd->iSubItem;
BOOL bItemSelected = ListView_GetItemState(hwnd, nItem, LVIS_SELECTED);
RECT subItemRect;
ListView_GetSubItemRect(hwnd, nItem, nSubItem, LVIR_BOUNDS, &subItemRect);
HBRUSH brsh=0;
if (bItemSelected)
{
brsh=CreateSolidBrush(RGB(255, 128, 128));
FillRect(hdc, &subItemRect,brsh);
}
else
{
brsh=CreateSolidBrush(RGB(51+nItem*30, 153, 255-nItem*30));
FillRect(hdc, &subItemRect,brsh);
}
if(brsh) DeleteObject(brsh);
TCHAR szText[260];
ListView_GetItemText(hwnd, nItem, nSubItem, szText, 260);
DrawText(hdc, szText, strlen(szText), &subItemRect, dwStyle);
}
return nResult;
}
代码如上,始终无法进入CDDS_ITEMPREPAINT | CDDS_SUBITEM,能进入CDDS_PREPAINT消息。
CreateWindow时已经加入了LVS_REPORT样式。
希望大神指教一二。 |
|