日期:2014-05-18 浏览次数:20956 次
private void Form1_Load(object sender, EventArgs e) { imageList1.Images.Clear(); treeView1.Nodes.Clear(); foreach (string cpname in Directory.GetLogicalDrives()) { if (cpname == "C:\\") { continue; } Win32.SHFILEINFO shfi = new Win32.SHFILEINFO(); DirectoryInfo dir = new DirectoryInfo(cpname); //获得图标 Win32.SHGetFileInfo(cpname, (uint)0x80, ref shfi, (uint)System.Runtime.InteropServices.Marshal.SizeOf(shfi), (uint)(0x100 | 0x400)); //取得Icon和TypeName //添加图标 imageList1.Images.Add(dir.Name, (Icon)Icon.FromHandle(shfi.hIcon).Clone()); TreeNode node = new TreeNode(dir.Name); node.ImageIndex = imageList1.Images.Count - 1; node.SelectedImageIndex = imageList1.Images.Count - 1; node.Name = dir.FullName; treeView1.Nodes.Add(node); Win32.DestroyIcon(shfi.hIcon); node.Nodes.Add(lsnode); node.Tag = true; } treeView1.CollapseAll(); } /// <summary> /// 针对文件目录 /// </summary> private void GetListViewItem(string path, TreeNode snode) { string[] dirs = Directory.GetDirectories(path); string[] files = Directory.GetFiles(path); Win32.SHFILEINFO shfi = new Win32.SHFILEINFO(); for (int i = 0; i < dirs.Length; i++) { try { DirectoryInfo dir = new DirectoryInfo(dirs[i]); if (dir.Name == "auto.exe" || dir.Name == "Autorun.inf" || dir.Name == "RECYCLER" || dir.Name == "System Volume Information" || dir.Name == "$RECYCLE.BIN") continue; //获得图标 Win32.SHGetFileInfo(dirs[i], (uint)0x80, ref shfi, (uint)System.Runtime.InteropServices.Marshal.SizeOf(shfi), (uint)(0x100 | 0x400)); //取得Icon和TypeName //添加图标 imageList1.Images.Add(dir.Name, (Icon)Icon.FromHandle(shfi.hIcon).Clone()); TreeNode node = new TreeNode(dir.Name); node.Name = dir.FullName; node.ImageIndex = imageList1.Images.Count - 1; node.SelectedImageIndex = imageList1.Images.Count - 1; node.Tag = true; snode.Nodes.Add(node); node.Nodes.Add(lsnode); Win32.DestroyIcon(shfi.hIcon); } catch { } } for (int i = 0; i < files.Length; i++) { try { FileInfo fi = new FileInfo(files[i]); //获得图标 Win32.SHGetFileInfo(files[i], (uint)0x80, ref shfi, (uint)System.Runtime.InteropServices.Marshal.SizeOf