On 19 Feb., 16:48, "Robert Ludig" <schwertfischtr omb...@gmx.dewr ote:
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(La youtKind.Sequen tial)]
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("comc tl32.dll")]
public extern static bool ImageList_SetOv erlayImage(int himl,
int iImage, int iOverlay);
[DllImport("user 32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int
wParam, int lParam);
public Form1()
{
InitializeCompo nent();
}
private void Form1_Load(obje ct sender, EventArgs e)
{
listView1.Items .Add("aa", 0);
}
private void button1_Click(o bject sender, EventArgs e)
{
LVITEM item = new LVITEM();
item.stateMask = 0x0F00; /*LVIS_OVERLAYMA SK*/
item.state = 1 << 8 /*INDEXTOOVERLAY MASK(1)*/;
ImageList_SetOv erlayImage(imag eList1.Handle.T oInt32(), 1,
1);
int x = SendMessage(thi s.listView1.Han dle.ToInt32(),
0x1000 + 43/*LVM_SETITEMSTA TE*/, -1/*all items*/,
((IntPtr)GCHand le.Alloc(item)) .ToInt32());
}
......