【问题标题】:Detecting file-selection in Windows Explorer [closed]在 Windows 资源管理器中检测文件选择 [关闭]
【发布时间】:2012-11-18 00:31:25
【问题描述】:

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

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

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

【问题讨论】:

  • 你读过thisthis吗?
  • thanyou,khillang,是的,我读过它们。但我仍然很困惑。我需要一个清晰的 C# 代码。
  • 我正在尝试这个:IShellFolderViewDual2
  • 任何人都可以帮助我吗?在Window 7中,资源管理器窗口底部有一个详细信息栏,当用户选择一个文件时,该栏将显示有关该文件的更多详细信息。这正是我想做的。
  • 正确的做法是不要尝试向 Explorer 注入额外的内容,而是自己托管 Explorer(ExplorerBrowser 对象)并监听选择事件。

标签: c# windows hook windows-explorer


【解决方案1】:

看看这个例子来获取鼠标点击或选中的事件:

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);
                }
            }
        }
    }

【讨论】:

  • 这会在桌面上找到突出显示的文件吗?
【解决方案2】:

只是在 Renier 的回答中添加一些内容:

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

【讨论】:

  • 如果您使用SHDocVw.ShellWindows() 而不是SHDocVw.ShellWindowsClass(),那么您将不必摆弄“嵌入互操作类型”设置。见stackoverflow.com/a/4174056/1172352
猜你喜欢
  • 1970-01-01
  • 2011-02-22
  • 2021-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-05
  • 2012-06-22
相关资源
最近更新 更多