win32 sdk 列表视图控件绘制

来源:互联网 发布:fyzf后缀是什么软件 编辑:程序博客网 时间:2024/06/01 12:18

微笑

 

//////////////////////////////////////////////////////////////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));//yellowFillRect(hdc, &subItemRect,brsh);}else{// not Selectedbrsh=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;}


 

关键:
else
{// not Selected
brsh=CreateSolidBrush(RGB(51+nItem*30, 153, 255-nItem*30));
FillRect(hdc, &subItemRect,brsh);
}