views:

337

answers:

2

I'm having a problem on Vista with the Listview control, in particular setting custom icons on the header. Normally under XP or any of the previous version of Windows, if I added an icon (in C++), I could do so with the following:

HeaderItem.mask     = HDI_FORMAT | HDI_IMAGE;
Header_GetItem(HeaderHWND, Column, &HeaderItem);

TurnOn(HeaderItem.fmt, HDF_IMAGE);
HeaderItem.iImage = Image;
if (Header_SetItem(HeaderHWND, Column, &HeaderItem) == 0)
    printf("Failed to set header [%d:%.8X]\n", GetLastError(), GetLastError());

and then to remove the image, on a particular column, I could use the same process but instead of turning on the HDF_IMAGE bit, you just turn it off.

On Vista, however, when I turn it off it doesn't seem to actually be accepting the change. So, for instance, when I start my fmt is:

0x4000 (or basically HDF_STRING)

I turn on the icon, and it becomes:

0x5800 (or basically HDF_STRING | HDF_IMAGE | HDF_BITMAP_ON_RIGHT)

I then turn it off again, but the result is:

0x4800 (or basically HDF_STRING | HDF_IMAGE)

I've checked, and I setting it to HDF_STRING only, but once HDF_IMAGE is set, it seems to be impossible to remove. Header_SetImage doesn't return any errors, so I'm at a loss as far as what to do. I've also tried removing the Imagelist from the control, but it still leaves the space as if there still was an image there.

At the end of the day I need to be able to add and remove icons from the header, and when they are removed I need all the header space available again (as they were before any were displayed. Any help would be greatly appreciated - thanks in advance!

A: 

Uhg, I just figured it out - they've changed slightly the way things work now as far as passed parameters.

Before, I always set the iImage to 0 when I was removing the HDF_IMAGE attribute - but it looks like now if you perform a Set, and your mask includes HDI_IMAGE, then it will not remove the HDF_IMAGE bit, even though you explicitly do.

So, the solution is to make sure not to send anything image-related if you're trying to remove it. Since I scoured the net and couldn't find anything about this, hopefully this post will now help anyone else who has a similar problem.

Mark
+1  A: 

If you read the documentation http://msdn.microsoft.com/en-us/library/bb775247(VS.85).aspx, if you indicate HDI_IMAGE in mask then iImage should be a valid index, you have to set it to I_IMAGENONE in order to remove it.

If you want to remve an image you have to do something like this:

HeaderItem.mask = HDI_FORMAT | HDI_IMAGE;
Header_GetItem(HeaderHWND, Column, &HeaderItem);
HeaderItem.fmt &= ~(HDF_IMAGE | HDF_BITMAP_ON_RIGHT);
HeaderItem.iImage = I_IMAGENONE;
Header_SetItem(HeaderHWND, Column, &HeaderItem);
Ismael
Yes, I see that on their online docs - the docs to VS2005 don't reflect that (they don't mention the I_IMAGENONE). My frustration is that it worked before regardless of whether you set iImage or not, and that it was silently failing. At least now I have two options - thanks! :)
Mark