求助关于SHMultiFileProperties的问题

jcqstc 2012-05-18 11:43:32
SHMultiFileProperties的第一个参数是一个自定义的IDataObject。

我个人不是很懂怎么去构造这个IDataObject,虽然参数说明里的那些数据我都有,但就是不知道怎么用。

求一个SHMultiFileProperties的调用例子,特别是有IDataObject的使用。
...全文
112 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
effun 2012-05-18
  • 打赏
  • 举报
回复
上面代码有一行多余的,粘贴过来没有注意看。
effun 2012-05-18
  • 打赏
  • 举报
回复
.net已经有IDataObject的实现,只要正确使用就可以了。其实答案很容易找,Google一下前几条就有,参考以下代码:


[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 void button2_Click(object sender, EventArgs e)
{

var data = new DataObject();
var files = new StringCollection() { @"c:\temp\2010_12_21 9_11_21.jpg", @"c:\temp\2010_12_21 9_09_31.jpg" };
data.SetFileDropList(files);
data.SetData("Preferred DropEffect", true, new MemoryStream(new byte[] { 5, 0, 0, 0 }));
data.SetData("Shell IDList Array", true, CreateShellIDList(files));
Clipboard.SetDataObject(data, true);

SHMultiFileProperties(data, 0);
}

private static MemoryStream CreateShellIDList(StringCollection filenames)
{
// first convert all files into pidls list
int pos = 0;
byte[][] pidls = new byte[filenames.Count][];
foreach (var filename in filenames)
{
// Get pidl based on name
IntPtr pidl = ILCreateFromPath(filename);
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
var memStream = new MemoryStream();
var 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 (var pidl in pidls)
{
sw.Write(pidlOffset);
pidlOffset += pidl.Length;
}

// Write the root pidl (0) followed by all pidls
sw.Write(0);
foreach (var pidl in pidls) sw.Write(pidl);
// stream now contains the CIDL
return memStream;
}



此代码在Win7下通过测试,但据原作者说在XP下无法正常工作,我没有环境没办法测试,这里有一篇文章可能会有帮助,楼主自己去发现吧。
http://www.zaoxue.com/article/tech-31614.htm
内容概要:本文档围绕基于MATLAB/Simulink平台的直流无刷电机速度控制系统展开,重点介绍利用Simulink搭建电机控制模型,实现直流无刷电机的速度开环控制仿真。文档详细阐述了系统建模、关键模块设计与参数配置过程,帮助读者深入理解电机控制的基本原理与仿真流程。同时,文档还列举了涵盖电力电子、新能源系统、路径规划、智能优化算法等多个领域的丰富仿真案例,充分展示了MATLAB/Simulink在多学科交叉科研仿真中的强大功能与广泛应用前景。; 适合人群:具备一定自动控制理论基础和MATLAB/Simulink使用经验的高校学生、科研人员及工程技术人员,特别适用于从事电机控制、电力电子、新能源系统、智能优化等方向的研究者。; 使用场景及目标:①学习直流无刷电机的工作原理及其速度开环控制方法;②掌握使用Simulink进行电机控制系统建模与仿真的核心技能;③为后续开展更高级的闭环控制、矢量控制或结合智能优化算法的电机控制研究奠定坚实的技术基础并提供实用的参考实例。; 阅读建议:建议读者结合文档提供的仿真模型与代码资源,亲自动手实践Simulink建模全过程,逐步理解各功能模块的作用与参数整定方法,并充分利用网盘中的配套资料进行复现与深入学习,从而有效提升科研仿真与工程实践能力。

111,132

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧