解决方案 »

  1.   

    这个需要自绘CListCtrl控件,codeproject上很多实例
      

  2.   

    可以自绘实现,派生CListCtrl类,添加处理虚函数DrawItem
      

  3.   

    SDK://////////////////////////////////////////////////////////////
    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 | CDRF_NOTIFYPOSTPAINT;
    }
    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));
    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);
    //
    if(nSubItem==0)
    {//OutputDebugString("bmp\n");
    RECT iconRect;
    ListView_GetSubItemRect(hwnd, nItem, nSubItem, LVIR_ICON, &iconRect);
    OffsetRect(&iconRect, -1, 0);
    HBITMAP oldbmp=(HBITMAP)SelectObject(g_hMemDC,g_hbmNormal);
    BitBlt(hdc,iconRect.left, iconRect.top, 16, 16,g_hMemDC,0,0,SRCCOPY);
    SelectObject(hdc,oldbmp);
    }
    //
    TCHAR szText[260];
    ListView_GetItemText(hwnd, nItem, nSubItem, szText, 260);
            OffsetRect(&subItemRect, 18, 0);
    DrawText(hdc, szText, strlen(szText), &subItemRect, dwStyle);
    return nResult;
    }
    else if (CDDS_ITEMPOSTPAINT == lpNMCustomDraw->nmcd.dwDrawStage)
    {// draw (horizantal line)
    HPEN hpen=CreatePen(PS_SOLID,1,RGB(0,255,0));
    HPEN holdpen=(HPEN)SelectObject(lpNMCustomDraw->nmcd.hdc,hpen);
    RECT crc;
    GetClientRect(hwnd,&crc);
    RECT irc;
    ListView_GetItemRect(hwnd, lpNMCustomDraw->nmcd.dwItemSpec,&irc,LVIR_BOUNDS);
    HDC hdc = lpNMCustomDraw->nmcd.hdc; 
    MoveToEx(hdc,0,irc.top,0);
    LineTo(hdc,crc.right-crc.left,irc.top);
    SelectObject(hdc,holdpen);
    //
    return CDRF_DODEFAULT;
    }
    return nResult;
    }
     ListViewCustomDraw
      

  4.   

    这个问题已经回答很多次了,可惜没一个人对这个有兴趣。有一次还被向立天以无满意答案而结贴,我实在无语了。
    typedef HRESULT (WINAPI *SETWINDOWTHEME)(HWND, LPCWSTR, LPCWSTR);
    // 纯 C 风格
    HMODULE hinstDLL = LoadLibrary(TEXT("uxtheme.dll"));
    if (hinstDLL != NULL) {
        SETWINDOWTHEME pfnSWT = (SETWINDOWTHEME)GetProcAddress(hinstDLL, "SetWindowTheme");
        if (pfnSWT != NULL) {
            (*pfnSWT)(hwndList, L"explorer", NULL);
        }
        FreeLibrary(hinstDLL);
    }
    // 在 MFC 中使用
    HMODULE hinstDLL = ::LoadLibrary(TEXT("uxtheme.dll"));
    if (hinstDLL != NULL) {
        SETWINDOWTHEME pfnSWT = (SETWINDOWTHEME)::GetProcAddress(hinstDLL, "SetWindowTheme");
        if (pfnSWT != NULL) {
            (*pfnSWT)(m_List.GetSafeHwnd(), L"explorer", NULL);
        }
        ::FreeLibrary(hinstDLL);
    }
      

  5.   


    这本功能本来就是系统提供的,并且 MSDN 上也说过:当然,前提是你系统开启了主题并且界面也启用了主题效果(右)。
    如果还是 Windows 2000 的那种窗口(左),你用这个代码没效果: