zoukankan      html  css  js  c++  java
  • 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);
    }

  • 相关阅读:
    【转载】C++汇编器、连接器
    【转载】vi的使用命令
    JDK,SDK,JRE概念
    iOS 使用xmpp做聊天客户端
    cocopods安装
    用XMPP实现完整Android聊天项目
    xmpp发送文件
    ember.js学习笔记
    html5 drag and drop
    jquery 数组深拷贝
  • 原文地址:https://www.cnblogs.com/lidabo/p/3701589.html
Copyright © 2011-2022 走看看