微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从C#应用程序获取WindowsExplorer中的当前select?

是否有可能从我的C#应用​​程序获取当前在Windows资源pipe理器中select的文件的列表?

我已经做了很多关于从C#这样的托pipe语言与Windows资源pipe理器交互的不同方法的研究。 最初,我正在研究shell扩展的实现( 在这里和这里例如),但显然这是从托pipe代码中的一个坏主意,可能无论如何对我的情况可能矫枉过正。

接下来,我看着PInvoke / COM解决scheme,并find这篇文章 ,这导致我这样的代码

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); string filename; ArrayList windows = new ArrayList(); foreach(SHDocVw.InternetExplorer ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if(filename.Equals("explorer")) { Console.WriteLine("Hard Drive: {0}",ie.LocationURL); windows.Add(ie); var shell = new Shell32.Shell(); foreach (SHDocVw.InternetExplorerMedium sw in shell.Windows()) { Console.WriteLine(sw.LocationURL); } } }

…但个别的InternetExplorer对象没有获得当前文件select的方法,虽然它们可以用来获取有关窗口的信息。

在MonoDevelop和Visual Studio上使用生成后脚本生成项目的最佳方法是什么?

进程启动作为域pipe理员从用户启动进程与UAC在域networking中激活

为什么相同的代码大小会产生不同大小的exe文件

SharpSSH .NET Library:无法从.NET连接到Linux(Debian)

如何用命令行压缩指定的文件

然后我发现这篇文章正是我所需要的,但在C ++中。 以此为出发点,我试图通过在我的项目中添加shell32.dll作为参考进行一些翻译。 我结束了以下几点:

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); string filename; ArrayList windows = new ArrayList(); foreach(SHDocVw.InternetExplorer ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if(filename.Equals("explorer")) { Console.WriteLine("Hard Drive: {0}",ie.LocationURL); windows.Add(ie); var shell = (Shell32.IShelldispatch4)new Shell32.Shell(); Shell32.Folder folder = shell.NameSpace(ie.LocationURL); Shell32.FolderItems items = folder.Items(); foreach (Shell32.FolderItem item in items) { ... } } }

这是稍微接近,因为我能够得到一个Folder对象的窗口,并为每个项目,但我仍然没有看到一种方式来获取当前的select。

我可能完全看错了地方,但我一直在追踪我唯一的线索。 任何人都可以指点我适当的PInvoke / COM解决scheme吗?

如何将新string添加到REG_MULTI_SZtypes的registry项?

从C#中selectsql Server数据库中的特定logging

如何使.NET应用程序“大地址感知”?

使用远程桌面的远程计算机的MachineName

即使计算机进入待机模式,窗口应用程序能否继续运行?

最后想出了一个解决方案,感谢这个问题: 使用WinAPI获取文件夹的选定项目 。

我结束了以下,为了得到当前选定的文件列表:

IntPtr handle = GetForegroundWindow(); List<string> selected = new List<string>(); var shell = new Shell32.Shell(); foreach(SHDocVw.InternetExplorer window in shell.Windows()) { if (window.HWND == (int)handle) { Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems(); foreach(Shell32.FolderItem item in items) { selected.Add(item.Path); } } }

显然window.Document对应于资源管理器窗口内的实际文件夹视图,这不是很直观。 但是,除了误导性的变量/方法名称,这完美的作品。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐