• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#SHMultiFileProperties查看多个文件属性

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
[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);


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#委托的发展史:.Net1.x委托=.Net2.x匿名方法=.Net3.0/3.5Lambda表达式 ...发布时间:2022-07-13
下一篇:
C#使用xpath找到一个节点发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap