• 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);
    }

  • 相关阅读:
    并查集(Java实现)
    Flask入门HelloWorld
    归并排序及优化(Java实现)
    用IDEA生成javadoc文档
    windows下安装Virtualenvwrapper
    模板方法模式Template Method(Java实现)
    部署Flask项目到腾讯云服务器CentOS7
    冒泡排序及优化(Java实现)
    迭代器模式Iterator(Java实现)
    堆排序(Java数组实现)
  • 原文地址:https://www.cnblogs.com/lidabo/p/3701589.html
Copyright © 2020-2023  润新知