DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
[cpp] view plaincopy
 
  1. //////////////////////////////////////////////////////////////  
  2. LRESULT ListViewCustomDraw(HWND hwnd, LPARAM lParam)  
  3. {  
  4.     LPNMHDR pnmh = (LPNMHDR) lParam;  
  5.           
  6.     if (pnmh->code != NM_CUSTOMDRAW) return 0;  
  7.           
  8.     LPNMLVCUSTOMDRAW lpNMCustomDraw = (LPNMLVCUSTOMDRAW) lParam;  
  9.   
  10.     int nResult = CDRF_DODEFAULT;   
  11.       
  12.     if (CDDS_PREPAINT == lpNMCustomDraw->nmcd.dwDrawStage)  
  13.     {  
  14.         nResult = CDRF_NOTIFYITEMDRAW;  
  15.     }  
  16.     else if (CDDS_ITEMPREPAINT == lpNMCustomDraw->nmcd.dwDrawStage)  
  17.     {  
  18.         nResult = CDRF_NOTIFYSUBITEMDRAW;  
  19.     }  
  20.     else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == lpNMCustomDraw->nmcd.dwDrawStage)  
  21.     {  
  22.         nResult = CDRF_SKIPDEFAULT;  
  23.           
  24.         const DWORD dwStyle = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS;  
  25.           
  26.         HDC hdc = lpNMCustomDraw->nmcd.hdc;   
  27.         SetBkMode(hdc,TRANSPARENT);  
  28.         int nItem = (int)lpNMCustomDraw->nmcd.dwItemSpec;   
  29.         int nSubItem = lpNMCustomDraw->iSubItem;   
  30.           
  31.         BOOL bItemSelected = ListView_GetItemState(hwnd, nItem, LVIS_SELECTED);  
  32.           
  33.         RECT subItemRect;  
  34.         ListView_GetSubItemRect(hwnd, nItem, nSubItem, LVIR_BOUNDS, &subItemRect);  
  35. //        
  36.         HBRUSH brsh=0;   
  37.         if (bItemSelected)  
  38.         {   //OutputDebugString("bItemSelected\n");  
  39.             brsh=CreateSolidBrush(RGB(255, 128, 128));//yellow  
  40.             FillRect(hdc, &subItemRect,brsh);  
  41.         }  
  42.         else  
  43.         {// not Selected  
  44.             brsh=CreateSolidBrush(RGB(51+nItem*30, 153, 255-nItem*30));  
  45.             FillRect(hdc, &subItemRect,brsh);  
  46.         }  
  47.         if(brsh) DeleteObject(brsh);  
  48. //  
  49.         TCHAR szText[260];  
  50.         ListView_GetItemText(hwnd, nItem, nSubItem, szText, 260);  
  51.         DrawText(hdc, szText, strlen(szText), &subItemRect, dwStyle);  
  52.     }  
  53.     return nResult;  
  54. }  


 

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

posted on   DoubleLi  阅读(1552)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示