C#:如何使用 SHOpenFolderAndSelectItems
有人可以举例说明如何使用 shell 函数 SHOpenFolderAndSelectItems< /a> 来自 C#?我不太明白如何使用这些功能,并且在 pinvoke.net 上找不到它。 .. =/
假设我有三个名为
X:\Pictures\a.jpg
X:\Pictures\s.jpg
X:\Pictures\d. 夹
然后我想用 a.jpg
、s.jpg
和 打开
X:\Pictures
文件 d.jpg 已选择。
Could someone give an example on how to use the shell function SHOpenFolderAndSelectItems from C#? I don't quite get how to use these kind of functions and couldn't find it on pinvoke.net... =/
Say I have three files called
X:\Pictures\a.jpg
X:\Pictures\s.jpg
X:\Pictures\d.jpg
I then want to open up the X:\Pictures
folder with a.jpg
, s.jpg
and d.jpg
selected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在同事遇到问题后寻找答案时,我没有找到答案,所以我写了一个小课程来做到这一点。代码位于 Gist 上,我将在本文末尾粘贴当前版本。
使用您的示例文件,语法将是:
与低级 API 相比,我的代码有一些限制,主要是:
无论如何,这是 ShowSelectedInExplorer 类源代码:
Searching for an answer after a coworker had the issue I found none so I wrote a small class to do this. The code is on Gist and I will paste the current version at the end of this post.
With your sample files, the syntax will be :
There are some limitations to my code compared to the low level API, mainly :
Anyway, here is the ShowSelectedInExplorer class source code :
不是 100% 的答案,但此代码段显示了如何从 C# 在资源管理器中选择单个项目。
Not a 100% answer, but this snippet shows how to select a single item in the explorer from C#.
查看http://www.cnblogs.com/qiuyi21/archive /2009/06/24/1510592.html。该示例在启动 SHOpenFolderAndSelectItems 之前使用 IShellLink 从路径获取 pidls,我将使用 ILCreateFromPath 代替。
Check http://www.cnblogs.com/qiuyi21/archive/2009/06/24/1510592.html. The example uses IShellLink to get pidls from path before launching SHOpenFolderAndSelectItems, I would use ILCreateFromPath instead.
SHOpoenFolderSelectedItems
的大部分需求将通过以下方式处理:对于 C# 中的文件选择,您通常会使用:System.Windows.Forms.OpenFileDialog。
对于 C# 中的文件夹选择,您通常会使用: System. Windows.Forms.FolderBrowserDialog。
您将设置适当的过滤器,并且最初可以设置选定的项目。
也许这足够接近您所需要的?
Most of the needs would of
SHOpoenFolderSelectedItems
would be handled by:For file selection in C# you would normally use: System.Windows.Forms.OpenFileDialog.
For folder selection in C# you would normally use: System.Windows.Forms.FolderBrowserDialog.
You would set an appropriate filter and you can set a selected item initially.
Perhaps this is close enough to what you need?