質問

Windowsエクスプローラーで選択されているファイルを知る方法はありますか?私はここに投稿されたチュートリアルを見てきましたへの馬鹿ガイド... 説明されるアクションは次のとおりです。

ホバー

コンテキスト

メニュープロパティ

ドラッグ

ドラッグアンドドロップ

ファイルが選択されたときに呼び出されるメソッドはあるのでしょうか。たとえば、ファイルのサムネイルビューを作成します。

ありがとう。

役に立ちましたか?

解決

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 .:これも見つかりました。 SendMessageを使用してSysListView32からC#のListViewアイテム
別のプロセスで動作させるにはブードゥー教が必要です...

フランスのサイト

他のヒント

このpythonスクリプトに出会いました。

from win32com.client.gencache import EnsureDispatch 

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

しかし、開いているフォルダーのみを取得し、そのフォルダーで現在選択されているアイテムは取得しません。

詳細は誰ですか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top