Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Windows资源管理器中检测文件选择_C#_Windows_Hook_Windows Explorer - Fatal编程技术网

C# 在Windows资源管理器中检测文件选择

C# 在Windows资源管理器中检测文件选择,c#,windows,hook,windows-explorer,C#,Windows,Hook,Windows Explorer,在Windows中,无论是在桌面上还是在Windows资源管理器中,我都希望检测文件或文件夹被选中(突出显示)的时刻。发生这种情况时,我希望显示一个消息框,显示文件或文件夹的全名 如果选择了多个项目,我希望显示所有项目 请注意,我的解决方案必须用C#编写。请查看此示例以获取鼠标单击或选定事件: 用下面的代码连接它,记住添加对SHDocVW.dll和Shell32.dll的引用,这将返回每个资源管理器中所有选定的项目和文件夹路径 public void GetListOfSelectedFile

在Windows中,无论是在桌面上还是在Windows资源管理器中,我都希望检测文件或文件夹被选中(突出显示)的时刻。发生这种情况时,我希望显示一个消息框,显示文件或文件夹的全名

如果选择了多个项目,我希望显示所有项目


请注意,我的解决方案必须用C#编写。

请查看此示例以获取鼠标单击或选定事件:

用下面的代码连接它,记住添加对SHDocVW.dll和Shell32.dll的引用,这将返回每个资源管理器中所有选定的项目和文件夹路径

public void GetListOfSelectedFilesAndFolderOfWindowsExplorer()
    {
        string filename;
        ArrayList selected = new ArrayList();
        var shell = new Shell32.Shell();
        //For each explorer
        foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows())
        {
            filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
            if (filename.ToLowerInvariant() == "explorer")
            {
                Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                foreach (Shell32.FolderItem item in items)
                {
                    MessageBox.Show(item.Path.ToString());
                    selected.Add(item.Path);
                }
            }
        }
    }

只是在雷尼尔的回答中添加了一些东西:

  • SHDocVW.dll和Shell32.dll位于文件夹C:\Windows\System32
  • 如果在SHDocVw.ShellWindowsClass()中出现错误,只需右键单击解决方案资源管理器上的SHDocVw引用即可 选择属性并设置 将互操作类型嵌入到false

你读过或吗?thanyou,khellang,是的,我读过。但我仍然感到困惑。我需要一个清晰的C代码。我正在尝试:IShellFolderViewDual2有人可以帮助我吗?在窗口7中,浏览器窗口底部有一个详细信息栏,当用户选择一个文件时,该栏将显示有关该文件的更多详细信息。这正是我想要做的。正确的方法不是尝试向资源管理器中注入额外的内容,而是自己托管资源管理器(ExplorerBrowser对象)并侦听选择事件。如果使用
SHDocVw.ShellWindows()
而不是
SHDocVw.ShellWindowsClass()
这样,您就不必再摆弄“嵌入互操作类型”设置了。请参阅。这会在桌面上查找高位文件吗?