public static void UseSystemImageList(ListView control)
{
IntPtr large, small;
int x, y;
if (control.LargeImageList == null)
{
control.LargeImageList = new System.Windows.Forms.ImageList();
}
if (control.SmallImageList == null)
{
control.SmallImageList = new System.Windows.Forms.ImageList();
}
Shell32.FileIconInit(true);
if (!Shell32.Shell_GetImageLists(out large, out small))
{
throw new Exception("Failed to get system image list");
}
ComCtl32.ImageList_GetIconSize(large, out x, out y);
control.LargeImageList.ImageSize = new System.Drawing.Size(x, y);
ComCtl32.ImageList_GetIconSize(small, out x, out y);
control.SmallImageList.ImageSize = new System.Drawing.Size(x, y);
User32.SendMessage(control.Handle, MSG.LVM_SETIMAGELIST, (int)LVSIL.LVSIL_NORMAL, LargeImageList);
User32.SendMessage(control.Handle, MSG.LVM_SETIMAGELIST, (int)LVSIL.LVSIL_SMALL, SmallImageList);
}