110,539
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
public static class getIcon
{
[DllImport("Shell32.dll")]
static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, int cbFileInfo, uint uFlags);
struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public int dwAttributes;
public char szDisplayName;
public char szTypeName;
}
static public Icon GetFileIcon(string fileName, bool smallIcon)
{
SHFILEINFO fi = new SHFILEINFO();
Icon ic = null;
int iTotal = (int)SHGetFileInfo(fileName, 100, ref fi, 0, (uint)(smallIcon ? 273 : 272));
if (iTotal > 0)
{
ic = Icon.FromHandle(fi.hIcon);
}
return ic;
}
}
public class TreeViewEx : TreeView
{
protected override void OnHandleCreated(EventArgs e)
{
SendMessage(this.Handle, TVM_SETEXTENDEDSTYLE, (IntPtr)TVS_EX_DOUBLEBUFFER, (IntPtr)TVS_EX_DOUBLEBUFFER);
base.OnHandleCreated(e);
}
private const int TVM_SETEXTENDEDSTYLE = 0x1100 + 44;
private const int TVM_GETEXTENDEDSTYLE = 0x1100 + 45;
private const int TVS_EX_DOUBLEBUFFER = 0x0004;
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}
public class ListViewEx : ListView
{
public ListViewEx()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}
TreeViewEx treeView1;
ListViewEx listView1;
public static int BrowNumber = 0, BrowRecord = 0, AssNumber = 0;
public class RecordBrow
{
public string Dir_Name;
public RecordBrow(string _name)
{
Dir_Name = _name;
BrowNumber += 1;
}
}
public static List<RecordBrow> recordBrows = new List<RecordBrow>();
public class FileAssociated
{
public int Id;
public string AssociatedType;
public Bitmap AssociatedIcon;
public FileAssociated(int _id, string _type, Bitmap _icon)
{
Id = _id;
AssociatedType = _type;
AssociatedIcon = _icon;
}
}
public static List<FileAssociated> fileAssociateds = new List<FileAssociated>();
public class DirectoryFile
{
public string Fullname;
public string DFname;
public string DFtype;
public int DFicon;
public string DFtime;
public long DFsize;
public int DFflag;
public DirectoryFile(string _full, string _name, string _type,int _icon, string _time,long _size,int _flag)
{
Fullname = _full;
DFname = _name;
DFtype = _type;
DFicon = _icon;
DFtime = _time;
DFsize = _size;
DFflag = _flag;
}
}
public static List<DirectoryFile> directoryFiles = new List<DirectoryFile>();
public Form1()
{
InitializeComponent();
treeView1 = new TreeViewEx()
{
ItemHeight = 22,
Size = new Size(376, 546),
Location = new Point(12, 41),
Font = new Font("微软雅黑", 9),
ImageList = imageList1,
ShowLines = false,
ShowRootLines = false,
ShowPlusMinus = false,
};
treeView1.NodeMouseClick += treeView1_NodeMouseClick;
this.Controls.Add(treeView1);
listView1 = new ListViewEx()
{
Size = new Size(515, 547),
Location = new Point(442, 40),
Font = new Font("微软雅黑", 9),
View = View.Details,
GridLines = false,
SmallImageList = imageList2,
FullRowSelect = true,
};
listView1.Columns.Add("文件名", 120, HorizontalAlignment.Left);
listView1.Columns.Add("文件类型", 120, HorizontalAlignment.Left);
listView1.Columns.Add("修改时间", 120, HorizontalAlignment.Left);
listView1.Columns.Add("大小", 120, HorizontalAlignment.Left);
listView1.DoubleClick += ListView1_DoubleClick;
this.Controls.Add(listView1);
ManagementObjectCollection queryCollection = getDrives();
treeView1.Nodes.Clear();
foreach (ManagementObject mo in queryCollection)
{
TreeNode node1 = new TreeNode();
node1.Text = mo["Name"].ToString();
node1.Name = mo["Name"].ToString() + "\\";
node1.ImageIndex = 0;
node1.Tag = 0;
treeView1.Nodes.Add(node1);
}
get_SubDirFile(treeView1.Nodes[0].Name);
SearchNode(treeView1.Nodes, treeView1.Nodes[0].Name);
recordBrows.Add(new RecordBrow(treeView1.Nodes[0].Name));
}
...................................................................................
.............................................................................