繁体   English   中英

在C#中监视资源管理器中的文件选择(例如剪贴板监视)

[英]Monitor file selection in explorer (like clipboard monitoring) in C#

我正在尝试创建一个小助手应用程序,一种情况是“文件复制查找器”。 我想做的是这样的:

  • 我启动我的C#.NET应用程序,它给了我一个空列表。
  • 启动普通的Windows资源管理器,在某些文件夹中选择一个文件
  • C#应用程序告诉我有关此文件的信息(例如重复项)

如何在“正常” Windows资源管理器实例中监视当前选择的文件。 我是否必须使用.NET启动实例才能处理该过程。 我需要一个句柄,还是可以在C#中监视某些“全局挂钩”? 有点像监视剪贴板,但不完全相同...

感谢任何帮助(如果您没有代码,只需将我指向正确的互操作程序,dll或帮助页面:-)谢谢,克里斯

编辑1(当前来源,感谢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);
        }
    }
}

您可以使用Shell自动化接口执行此操作。 基本过程是

  1. 在Shdocwv.dll和Shell32.dll上运行Tlbimp(或直接从VS添加引用)。
  2. 创建ShellWindows集合的实例并进行迭代。 这将同时包含Windows资源管理器和Internet Explorer窗口。
  3. 对于Windows资源管理器窗口,IWebBrowser2.Document属性将返回IShellFolderViewDual引用。
  4. IShellFolderViewDual具有可查询的SelectedItems方法和可处理的更改事件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM