显示器在资源管理器文件选择(如剪贴板监视)在C# [英] Monitor file selection in explorer (like clipboard monitoring) in C#

查看:238
本文介绍了显示器在资源管理器文件选择(如剪贴板监视)在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个小帮手的应用程序,一个方案是文件复制发现者。我想要做的是这样的:

  • 在我开始我的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);
        }
    }
}
 

解决方案

您可以与外壳自动化接口做到这一点。其基本过程是

  1. 运行TLBIMP上Shdocwv.dll和 SHELL32.DLL(或者直接添加 从VS参考)。
  2. 创建一个 在 ShellWindows 收集并循环。这会 同时包含Windows资源管理器和 Internet Explorer窗口。
  3. 有关 Windows资源管理器窗口,该 IWebBrowser2.Document将财产 返回 IShellFolderViewDual 参考。
  4. 的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

  1. Run Tlbimp on Shdocwv.dll and Shell32.dll (or directly add a reference from VS).
  2. Create an instance of the ShellWindows collection and iterate. This will contain both Windows Explorer and Internet Explorer windows.
  3. For Windows Explorer windows, the IWebBrowser2.Document property will return a IShellFolderViewDual reference.
  4. The IShellFolderViewDual has a SelectedItems method you can query and an event for changes you can handle.

这篇关于显示器在资源管理器文件选择(如剪贴板监视)在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆