在图像列表透明图像的列表视图 [英] Transparent images in ImageLists for ListViews

查看:167
本文介绍了在图像列表透明图像的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的节目的画面:

Here is a picture of my program:

正如你所看到的图标是不是透明的,只是白色。这是有问题的,因为我codeD上的列表视图交替的颜色,白色看起来灰色非常难看。

As you can see, the icons aren't transparent, simply white. This is problematic, because I've coded the list-view to alternate colors and the white looks very ugly on grey.

现在,我使用的是位图与图标的粉红色的背景和用粉红色作为掩模。这里的code我HIMAGELIST:

Right now, I'm using a bitmap with a pink background for the icons, and using the pink color as a mask. Here's the code for my HIMAGELIST:

hImageList = ImageList_Create(16, 16,  ILC_COLOR32 | ILC_MASK, ICON_COUNT, 0);
if (hImageList != NULL)
{
  HBITMAP hBitmap = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_ICONS));
  if (hBitmap != NULL)
  {
    ImageList_AddMasked(hImageList, hBitmap, RGB(0xFF, 0, 0xFF)); // pink mask
    DeleteObject(hBitmap);
  }

  ImageList_SetBkColor(hImageList, CLR_NONE);
}
ListView_SetImageList(hWnd, hImageList, LVSIL_SMALL);

下面是code的列表视图的自定义绘制(交替的颜色)

Here is the code for the list-view's Custom Draw (the alternating colors)

LRESULT WhiteFlagUI::PaintListView(__in HWND hwndListView, __in LPARAM lParam)
{
  LPNMLVCUSTOMDRAW lpListDraw = reinterpret_cast<LPNMLVCUSTOMDRAW>(lParam);

  switch (lpListDraw->nmcd.dwDrawStage)
  {
    case CDDS_PREPAINT:
      return (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYSUBITEMDRAW);
      break;

    case (CDDS_PREPAINT | CDDS_ITEM):
      {
        RECT rect;

        if (ListView_GetSubItemRect(hwndListView, lpListDraw->nmcd.dwItemSpec, lpListDraw->iSubItem, LVIR_BOUNDS, &rect))
        {
          COLORREF color;

          // determine color
          if (lpListDraw->nmcd.uItemState & CDIS_SELECTED)
            color = RGB(157, 173, 215);
          else if (lpListDraw->nmcd.dwItemSpec % 2)
            color = RGB(240, 240, 240);
          else
            color = RGB(255, 255, 255);

          // paint
          HBRUSH hBrush = CreateSolidBrush(color);
          if (hBrush != NULL)
          {
            FillRect(lpListDraw->nmcd.hdc, &rect, hBrush);
            DeleteObject(hBrush);
          }

          // return color info
          lpListDraw->clrTextBk = color;
          return CDRF_NEWFONT;
        }
      }
      break;
  }
  return CDRF_DODEFAULT;
}

坦率地说,我完全失去了对如何处理这个。没有人有任何想法?

Quite frankly, I'm completely lost as to how to approach this. Does anyone have any ideas?

推荐答案

我面临这个问题为好。
我已经加入SetBkColor解决它(RGB(...))其中RGB(...)从前景色交替背景一个自定义绘制过程英寸我用16×16 4B BMP白色背景。除了使用FillRect()的,我设置clrTextBk了。最后一个适用于文本。
当我从我的实验与CListCtrl中看到,函数SetBkColor()设置背景颜色只有图标和不文本(我发现文档中没有谈到这个)。

I was faced with this problem as well. I've solved it by adding SetBkColor(RGB(...)) where RGB(...) alternates from foreground color to background one in the custom draw procedure. I use 16x16 4b BMP with white background. Instead of using FillRect(), I set clrTextBk too. The last works for texts. As I see from my experiments with CListCtrl, function SetBkColor() sets background color for icons only and does not for text (I found nothing about this in docs).

这一切仅适用于非空项。以这种风格画空行,我重写OnEraseBkgnd()通知功能。对于完全空单,简单的矩形绘制。

All this works only for non-empty items. To draw empty rows with this style, I override OnEraseBkgnd() notification function. For fully empty list, simple rectangles are drawn.

我希望这将有助于

Olexiy

这篇关于在图像列表透明图像的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆