首页 > 代码库 > win32 sdk 列表视图控件绘制
win32 sdk 列表视图控件绘制
[cpp] view plaincopy
- //////////////////////////////////////////////////////////////
- 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));//yellow
- 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);
- //
- 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);
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。