By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

SetOverlayImage in windows forms ListView

P: n/a
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 ?

Feb 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 19 Feb., 16:48, "Robert Ludig" <schwertfischtromb...@gmx.dewrote:
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.ToInt3 2(), 1,
1);
int x = SendMessage(this.listView1.Handle.ToInt32(),
0x1000 + 43/*LVM_SETITEMSTATE*/, -1/*all items*/,
((IntPtr)GCHandle.Alloc(item)).ToInt32());
}
......
Feb 20 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.