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

标签 c# windows hook windows-explorer

<分区>

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

如果选择了多个项目,我想显示所有项目。

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

最佳答案

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

https://stackoverflow.com/questions/7222749/i-created-a-program-to-hide-desktop-icons-on-double-click-of-desktop-but-would-o

加入以下代码,记住添加对 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);
                }
            }
        }
    }

关于c# - 在 Windows 资源管理器中检测文件选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13436292/

相关文章:

c# - 在 C# 中获取部分字符串的正则表达式模式或算法

windows - git-svn 在 Windows 上忽略 subversion 配置文件 (auto-props)

c++ - Hook : why do we need to VirtualProtect() again to restore permissions?

liferay - 如何以编程方式在 liferay 中为用户分配站点管理角色?

C# 返回具有祖先和自身但没有其他子元素的 XML 元素

c# - 生成连续的字母数字 ID

c# - 使用 C# 将应用程序发送到特定屏幕

python - 尝试在 Python 中使用 Selenium 启动网页

java - 如何停止已执行的 Jar 文件

hook - 安卓应用程序: java/JNI call hooking strategies