问题描述
我想创建一个小帮手的应用程序,一个方案是文件复制发现者。我想要做的是这样的:
- 在我开始我的C#.NET应用程序,它给了我一个空列表。
- 启动正常的windows资源管理器,选中某个文件夹 文件
- 在C#的应用程序告诉我的东西有关此文件(如重复)
如何监控在正常Windows资源管理器实例当前选中的文件。我必须使用.NET有进程的句柄启动实例。我需要一个手柄,或者是有一些全局钩子我可以在里面C#监控。它有点像监视剪贴板,但不完全一样...
任何帮助是AP preciated(如果你没有code,只是点我正确的互操作性展示,DLL或帮助:-)感谢页面,克里斯
修改1(电流源,由于马蒂亚斯)
使用SHDOCVW;
使用SHELL32;
公共静态无效ListExplorerWindows()
{
的foreach(InternetExplorer的即在新ShellWindowsClass())
DebugExplorerInstance(即);
}
公共静态无效DebugExplorerInstance(InternetExplorer的实例)
{
的Debug.WriteLine(DebugExplorerInstance.PadRight(30,'='));
的Debug.WriteLine(全名+ instance.FullName);
的Debug.WriteLine(AdressBar+ instance.AddressBar);
VAR DOC = instance.Document为IShellFolderViewDual;
如果(文件!= NULL)
{
的Debug.WriteLine(doc.Folder.Title);
的foreach(在doc.SelectedItems的FolderItem项目())
{
的Debug.WriteLine(item.Path);
}
}
}
您可以与外壳自动化接口做到这一点。其基本过程是
- 运行TLBIMP上Shdocwv.dll和SHELL32.DLL(或者直接添加从VS参考)。
- 创建一个在 ShellWindows 收集并循环。这会同时包含Windows资源管理器和Internet Explorer窗口。
- 有关Windows资源管理器窗口,该IWebBrowser2.Document将财产返回 IShellFolderViewDual 参考。
- 的IShellFolderViewDual有SelectedItems方法,你可以查询和事件的变化您可以处理。
I am trying to create a little helper application, one scenario is "file duplication finder". What I want to do is this:
- I start my C# .NET app, it gives me an empty list.
- Start the normal windows explorer, select a file in some folder
- The C# app tells me stuff about this file (e.g. duplicates)
How can I monitor the currently selected file in the "normal" windows explorer instance. Do I have to start the instance using .NET to have a handle of the process. Do I need a handle, or is there some "global hook" I can monitor inside C#. Its a little bit like monitoring the clipboard, but not exactly the same...
Any help is appreciated (if you don't have code, just point me to the right interops, dlls or help pages :-) Thanks, Chris
EDIT 1 (current source, thanks to Mattias)
using SHDocVw;
using Shell32;
public static void ListExplorerWindows()
{
foreach (InternetExplorer ie in new ShellWindowsClass())
DebugExplorerInstance(ie);
}
public static void DebugExplorerInstance(InternetExplorer instance)
{
Debug.WriteLine("DebugExplorerInstance ".PadRight(30, '='));
Debug.WriteLine("FullName " + instance.FullName);
Debug.WriteLine("AdressBar " + instance.AddressBar);
var doc = instance.Document as IShellFolderViewDual ;
if (doc != null)
{
Debug.WriteLine(doc.Folder.Title);
foreach (FolderItem item in doc.SelectedItems())
{
Debug.WriteLine(item.Path);
}
}
}
You can do this with the shell automation interfaces. The basic process is to
- Run Tlbimp on Shdocwv.dll andShell32.dll (or directly add areference from VS).
- Create aninstance of the ShellWindowscollection and iterate. This willcontain both Windows Explorer andInternet Explorer windows.
- ForWindows Explorer windows, theIWebBrowser2.Document property willreturn a IShellFolderViewDualreference.
- The IShellFolderViewDualhas a SelectedItems method you canquery and an event for changes youcan handle.
这篇关于显示器在资源管理器文件选择(如剪贴板监视)在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!