Transparent images in ImageLists for ListViews

前端 未结 2 462
北海茫月
北海茫月 2021-01-07 07:40

Here is a picture of my program:

\"WhiteFlag\"

As you can see, the icons a

相关标签:
2条回答
  • 2021-01-07 08:09

    I found a bit of a hack around this problem. If you set the background image to a blank white bitmap using ListView_SetBkImage it will force the icons to draw transparently. Unfortunately, doing this causes NM_CUSTOMDRAW to ignore the background color set with CDRF_NEWFONT. To get around it, call FillRect to fill background of the item in CDDS_ITEMPREPAINT and return CDRF_DODEFAULT or CDRF_NEWFONT if you are changing the foreground color as well.

    0 讨论(0)
  • 2021-01-07 08:24

    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).

    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.

    I hope this will help

    Olexiy

    0 讨论(0)
提交回复
热议问题