1

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

  • 我启动我的 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);
        }
    }
}
4

1 回答 1

1

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

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