捕获Windows资源管理器事件

时间:2011-07-13 11:33:56

标签: windows explorer windows-explorer

我想编写一个在Windows资源管理器旁边运行的应用程序。每当用户选择文件夹或文件时,我想更新我的程序,因此用户可以对文件进行注释。

这就是它所要做的一切。信息将按文件保存。

是否可以在没有右键单击上下文菜单/(Windows shell?)的情况下执行此操作?

3 个答案:

答案 0 :(得分:1)

您可以使用BHO,在BHO DISPID_DOCUMENTCOMPLETE事件处理程序中,您将获得IShellFolderViewDual,以便您可以查找DIID_DShellFolderViewEvents的ConnectionPoint并重新访问DISPID_SELECTIONCHANGED事件,请参阅here了解详细信息

答案 1 :(得分:0)

您可以编写AutoHotkey脚本。以下脚本将每隔100ms检查一次,并显示一个系统工具提示,其中包含所选文件/文件夹的名称:

Previous=
Current=

Loop
{
    Current :=GetExplorerSel()
    If (Previous <> Current)
    {
        TrayTip, You have selected, %Current%, 10, 1
        Previous = %Current%
    }
    Sleep 100
}

GetExplorerSel(hwnd="") {
    hwnd := hwnd ? hwnd : WinExist("A")
    WinGetClass class, ahk_id %hwnd%
    if (class="CabinetWClass" or class="ExploreWClass")
    for window in ComObjCreate("Shell.Application").Windows
        if (window.hwnd==hwnd)
        {
            selected := window.Document.SelectedItems
            for item in selected
            ret .= item.path "`n"
            return Trim(ret,"`n")
        }
}

如果您想使用其他语言,只需查看 COM 即可与之互动。

答案 2 :(得分:0)

您可以在Windows窗体项目中创建FileSystemWatcher,该窗口项目在发生文件系统更改时触发。您可以在Visual Studio的工具箱中找到FileSystemWatcher。

https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx

您可以为每个驱动器创建一个观察程序(以编程方式),然后确保&#34;观看子文件夹和子文件夹项目&#34;也启用了。

相关问题