C# SHMultiFileProperties查看多个文件属性
2013-05-23 10:54
381 查看
[DllImport("shell32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SHMultiFileProperties(IDataObject pdtobj, int dwFlags); [DllImport("shell32.dll", CharSet = CharSet.Auto)] public static extern IntPtr ILCreateFromPath(string path); [DllImport("shell32.dll", CharSet = CharSet.None)] public static extern void ILFree(IntPtr pidl); [DllImport("shell32.dll", CharSet = CharSet.None)] public static extern int ILGetSize(IntPtr pidl); private static MemoryStream CreateShellIDList(System.Collections.Specialized.StringCollection filenames) { // first convert all files into pidls list int pos = 0; byte[][] pidls = new byte[filenames.Count][]; foreach (Object filename in filenames) { // Get pidl based on name IntPtr pidl = ILCreateFromPath(filename.ToString()); int pidlSize = ILGetSize(pidl); // Copy over to our managed array pidls[pos] = new byte[pidlSize]; Marshal.Copy(pidl, pidls[pos++], 0, pidlSize); ILFree(pidl); } // Determine where in CIDL we will start pumping PIDLs int pidlOffset = 4 * (filenames.Count + 2); // Start the CIDL stream MemoryStream memStream = new MemoryStream(); BinaryWriter sw = new BinaryWriter(memStream); // Initialize CIDL witha count of files sw.Write(filenames.Count); // Calcualte and write relative offsets of every pidl starting with root sw.Write(pidlOffset); pidlOffset += 4; // root is 4 bytes foreach (byte[] pidl in pidls) { sw.Write(pidlOffset); pidlOffset += pidl.Length; } // Write the root pidl (0) followed by all pidls sw.Write(0); foreach (byte[] pidl in pidls) sw.Write(pidl); // stream now contains the CIDL return memStream; } //调用: string[] strArr = new string[] { @"C:\Lee", @"c:\windows" }; System.Collections.Specialized.StringCollection coll = new System.Collections.Specialized.StringCollection(); coll.AddRange(strArr); DataObject data = new DataObject(); data.SetData("Preferred DropEffect", true, new MemoryStream(new byte[] { 5, 0, 0, 0 })); data.SetData("Shell IDList Array", true, CreateShellIDList(coll)); data.SetFileDropList(coll); SHMultiFileProperties(data, 0);
相关文章推荐
- C# SHMultiFileProperties查看多个文件属性
- Delphi SHMultiFileProperties查看多个文件属性
- Delphi SHMultiFileProperties查看多个文件属性
- 调用windows api SHMultiFileProperties 显示多文件的汇总属性
- C# 读取Properties属性文件
- SeeFiles:C#查看和修改文件或目录所有属性的工具
- file 查看文件属性
- Linux查看文件或目录属性
- java spring中对properties属性文件加密及其解密
- stat,查看文件属性
- (88)将系统属性输出到文件中Properties.list方法
- C# 查看所有的隐藏文件
- 使用JAVA读写Properties属性文件
- Mapper的XML映射文件---2.1: 属性(properties)
- 得到src目录下的properties文件属性
- Spring中属性文件properties的读取与使用
- 练习 2017-08-15 属性(Properties)类加载资源文件
- spring引入properties文件,并在controller等层获得引入文件中属性的值
- C#复制文件、设置隐藏,只读属性
- 微软XSD工具根据XSD文件生成的C#类中多余Specified属性问题