Explorer窗口遍历

本文分享了一段使用 AutoHotkey 通过 COM 对象 Shell.Application 遍历 Windows 资源管理器(Explorer)与 IE 窗口的示例代码。

本文分享了一段使用 AutoHotkey 通过 COM 对象 Shell.Application 遍历 Windows 资源管理器(Explorer)与 IE 窗口的示例代码。核心思路是利用该对象的 Windows 属性返回的 ShellWindows 集合,逐一枚举每个文件管理器/浏览器窗口,进而读取或操作窗口相关信息。

使用要点:先创建 Shell.Application 实例,再通过 obj.Windows 取得 ShellWindows 集合;遍历集合中的每个 ShellWindow 对象可访问其 Document、LocationName、LocationURL、HWND 等属性,据此判断并操纵对应窗口。需注意该集合同时涵盖资源管理器与旧版 IE 窗口,遍历时可按需过滤。本文代码基于 AHK v1 语法;AHK v2 中 COM 创建改用 ComObject,其余对象操作方式基本一致。

;~ COM Object: Shell.Application
;~ Purpose: Access Explorer & IE Windows/Tabs; Open & Manipulate Windows
;~ System Requirements: General
;~ Documentation Link: Shell Object
;~ Other Links: ShellWindows Collection
;~ Code Example:

;~ The Windows Property returns the ShellWindows Collection, which is extremely helpful for accessing Explorer/IE Windows. This example Enumerates all the Explorer & IE Windows/Tabs:
;~ Code:

SetFormat, IntegerFast, Hex ;// display HWND in Hex

for Item in ComObjCreate("Shell.Application").Windows ;// loop through the ShellWindows Collection
   data .=   "Name:`t" Item.LocationName "`n"
    . "URL:`t"   Item.LocationURL "`n"
    . "Prog:`t"  Item.Name "`n"
    . "`t"       Item.FullName "`n"
    . "HWND:`t"  Item.HWND "`n`n"

MsgBox %data%
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA捐赠
共{{data.count}}人
人已捐赠
教程

ExifMove v1.90增加了对可能生成重复文件的判断,重复文件时,会自动重命名,另可以手工输入目标目录和目标文件格式

2020-3-27 21:55:37

教程

GDIP例子进度条

2020-3-29 2:04:52

❯
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索