1

I'm not sure why I'm getting this black outline when I add an icon to the CListCtrl (or list-view control)?

enter image description here

I load it as such:

//HICON hIcon;
LoadIconWithScaleDown(theApp.m_hInstance, MAKEINTRESOURCE(Icon_ID), 15, 15, &hIcon);

I then create my image list as such:

//CImageList iml;
iml.Create(15, 15, ILC_COLOR32, numberIcons, 0);
iml.Add(hIcon);

the list view is prepped first:

//CListCtrl lst;
lst.SetExtendedStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | 
    LVS_EX_LABELTIP | LVS_EX_HEADERDRAGDROP | LVS_EX_SUBITEMIMAGES);
lst.ModifyStyle(0, LVS_SHOWSELALWAYS);

and the icon is displayed in the subitem of the list as such:

int nInd = lst.InsertItem(c, L"Main label");

lst.SetItem(nInd, nSubitemIndex, LVIF_TEXT | LVIF_IMAGE, L"2 files", nIconInd, 0, 0, 0);

So what am I doing wrong?

PS. I ran this test on my Windows 8.1 with a 32-bit trucolor display setting.

The icon itself though is a 256-color image since I don't see any reason to waste space on a 32-bit icon with an alpha channel for such a small size & simple design:

enter image description here

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 1
    since you have a white background you can just put the white color in there, but I believe you need an alpha channel if you want a transparency there – Marco A. Jun 17 '14 at 17:00
  • _" I don't see any reason to waste space on a 32-bit icon"_ - Is the time you're wasting on this problem really worth a saving few hundred bytes? – Captain Obvlious Jun 17 '14 at 17:01
  • The background depends on the user selection in CP. So it will not be necessarily white. As for adding alpha-channel icons -- it then looks OK on Win 8.1 but when I load the app in an older XP machine with a 16-bit color scheme, it still shows the black background. Plus I don't have just 1 icon. It's way more than that. – c00000fd Jun 17 '14 at 17:06
  • You configured the image list for 32 bit color with alpha and then supplied an image with no alpha. Supply an image with alpha and it's all good. – David Heffernan Jun 18 '14 at 06:34

3 Answers3

2

LVS_EX_FULLROWSELECT has transparency issues on XP, you are likely encountering that. You may have to owner-draw the images onto the list view to preserve the transparency. Or, load the images into one image list, then render a copy of the images with a background color matching the list view's color to a separate image list, and then use the second image list with the list view.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • @c00000fd: Yes, XP doesn't deal with transparency really well. If I were you I'd render _all_ of your list-views as custom-drawn. It's not that difficult. [Here's](http://www.codeproject.com/Articles/79/Neat-Stuff-to-Do-in-List-Controls-Using-Custom-Dra) a nice sample code that shows how to do it right. – ahmd0 Jun 17 '14 at 18:53
  • Doesn't seem to be related to XP. And XP handles transparency fine. Owner draw is certainly not needed here. – David Heffernan Jun 18 '14 at 06:33
2

Maybe water under the bridge by now, but I found colordepth settings of 8 bit on my offending imagelist. Setting it to 32 resulted in transpareency working as expected...

Mark
  • 21
  • 1
0

Check this thread here Getting alpha blending to work with CImageList

Adding this line one C++ file did the trick:

enter code here
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

Do not even ask... but it took me a long time to find that out

Community
  • 1
  • 1
BadJerry
  • 154
  • 1
  • 12