• win32 sdk 列表视图控件绘制


    [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 ");  
    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);
    }

  • 相关阅读:
    linux基础命令之一
    Chrome 控制台使用大全
    移动端效果 — 页面引入在线视频
    移动端——简单计分表单
    JS操作cookie
    移动端页面字体——rem的使用
    Highcharts 使用总结
    CSS水平居中
    python学习 day2
    python学习 day1
  • 原文地址:https://www.cnblogs.com/lidabo/p/3701589.html
Copyright © 2020-2023  润新知