public static IntPtr GetIconHandle(string path) { SHFILEINFO info; SHGetFileInfo(path, 0, out info, (uint)Marshal.SizeOf(typeof(SHFILEINFO)), 0x101u); return info.hIcon; }
private string GetImageKey(string path) { IntPtr h = SysIconHelper.GetIconHandle(path); string key = h.ToString(); if (treeView1.ImageList == null) { treeView1.ImageList = new ImageList(); treeView1.ImageList.ColorDepth = ColorDepth.Depth32Bit; } if (!treeView1.ImageList.Images.ContainsKey(key)) { treeView1.ImageList.Images.Add(key, Icon.FromHandle(h)); } return(key); }