How do I set overlay images for ListViewItems in a Windows Forms
ListView? I want to overlay an additional Icon on top of the
ListViewItem's icon. Since I can do this in MFC/Win32 I suppose this
API is somehow exposed in WindowsForms too ? Or do I have to use P/
Invoke myself? If so, is there an (c#, VB.NET) example around
somewhere that shows me how to do it ?
I tried the followinng simple code. Do you see any mistakes (because
sendmessage returns 1, but nothing happens - no overlay image is
set) ?:
[StructLayout(LayoutKind.Sequential)]
struct LVITEM
{
public uint mask;
public int iItem;
public int iSubItem;
public uint state;
public uint stateMask;
public string pszText;
public int cchTextMax;
public int iImage;
public int lParam;
public int iIndent;
public int iGroupId;
public uint cColumns;
public uint puColumns;
}
public partial class Form1 : Form
{
[DllImport("comctl32.dll")]
public extern static bool ImageList_SetOverlayImage(int himl,
int iImage, int iOverlay);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int
wParam, int lParam);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listView1.Items.Add("aa", 0);
}
private void button1_Click(object sender, EventArgs e)
{
LVITEM item = new LVITEM();
item.stateMask = 0x0F00; /*LVIS_OVERLAYMASK*/
item.state = 1 << 8 /*INDEXTOOVERLAYMASK(1)*/;
ImageList_SetOverlayImage(imageList1.Handle.ToInt32(), 1,
1);
int x = SendMessage(this.listView1.Handle.ToInt32(),
0x1000 + 43/*LVM_SETITEMSTATE*/, -1/*all items*/,
((IntPtr)GCHandle.Alloc(item)).ToInt32());
}
......