2008-10-24 71 views
3

有沒有辦法知道在Windows資源管理器中選擇哪個文件?我一直在尋找在這裏Idiots guide to ...張貼的教程,但所描述的動作是:所選文件的外殼擴展

懸停

方面

菜單屬性

拖放

我想知道是否有一個方法在選擇文件時被調用。例如創建文件的縮略圖視圖。

謝謝。

回答

0

這是我如何做,在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 
} 

而且我從資源管理器(這是容易出現問題的編輯字段中的路徑可以不存在或可以設置不顯示!完整路徑)。

的核心思想是要求資源的SysListView32控制哪些選定的項目,並得到他們。現在

,這是一個黑客,也有可能是更清潔的方式...

PS:也發現了這個:Getting ListView items in C# from SysListView32 using SendMessage
需要一些巫術得到它的工作在另一個進程...

房地產代碼在a French site

0

我遇到了這個python腳本。

from win32com.client.gencache import EnsureDispatch 

for w in EnsureDispatch("Shell.Application").Windows(): 
    print w.LocationName + "=" + w.LocationURL 

但我只得到打開的文件夾,而不是該文件夾中當前選定的項目。

任何人都有更多信息?