【问题标题】:Shell extension for selected file所选文件的外壳扩展名
【发布时间】:2008-10-24 00:22:48
【问题描述】:

有没有办法知道在 Windows 资源管理器中选择了哪个文件?我一直在看这里发布的教程Idiots guide to ...,但描述的操作是:

悬停

上下文

菜单属性

拖动

拖放

我想知道是否有在选择文件时调用的方法。例如创建文件的缩略图视图。

谢谢。

【问题讨论】:

    标签: selecteditem shell-extensions


    【解决方案1】:

    这是我在 AutoHotkey 中的操作方式:

    GetWindowsExplorerSelectedFile(_hWnd)
    {
        local selectedFiles, file
    
        ; I can send ^C and parse Clipboard, but this way don't mess with clipboard at all, seems nicer.
        ; Warning: with this, you get only what is displayed in Explorer!
        ; If you kept the default Windows setting of not displaying file extensions (bad idea...),
        ; you will get partial file names...
        ControlGet, selectedFiles, List, Selected Col1, SysListView321, ahk_id %_hWnd%
        Loop, Parse, selectedFiles, `n  ; Rows are delimited by linefeeds (`n).
        {
            If (A_Index = 1)
            {
                file := A_LoopField
            }
            Else
            {
                ; Indicate that several files are selected, we return only the first one
                ; but count the total number of selected files, to indicate we return a partial result
                ErrorLevel := A_Index
            }
        }
        Return file
    }
    

    我从资源管理器的编辑字段中获取路径(这很容易出现问题!可以不存在或可以设置为不显示完整路径)。

    核心思想是询问Explorer的SysListView32控件被选中的项目是什么,并得到它们。

    现在,这是一个 hack,可能有更清洁的方法......

    PS.:还发现了这个:Getting ListView items in C# from SysListView32 using SendMessage
    需要一些巫术来让它在另一个进程上工作......

    a French site的真实代码!

    【讨论】:

      【解决方案2】:

      我遇到了这个 python 脚本。

      from win32com.client.gencache import EnsureDispatch 
      
      for w in EnsureDispatch("Shell.Application").Windows(): 
          print w.LocationName + "=" + w.LocationURL 
      

      但我只得到打开的文件夹,而不是该文件夹中当前选定的项目。

      有人知道更多信息吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-16
        • 1970-01-01
        相关资源
        最近更新 更多