找回密码
 加入
搜索
查看: 2882|回复: 6

[AU3基础] 如何枚举所有类似标题的窗口的句柄[已解决]

[复制链接]
发表于 2016-11-13 00:08:08 | 显示全部楼层 |阅读模式
本帖最后由 cashiba 于 2016-11-14 13:20 编辑
我叫mt_淘宝搜索 - Microsoft Internet Explorer
我叫mt_网页搜索 - Microsoft Internet Explorer
狗狗搜索-我叫mt - Microsoft Internet Explorer
我叫mt - 必应 Bing - Microsoft Internet Explorer
我叫mt - Google 搜索 - Microsoft Internet Explorer
我叫mt?-?搜狗搜索 - Microsoft Internet Explorer
我叫mt - 有道搜索 - Microsoft Internet Explorer
我叫mt - 搜搜更懂你 - Microsoft Internet Explorer
百度搜索_我叫mt - Microsoft Internet Explorer
我叫mt 第四季_淘宝搜索 - Microsoft Internet Explorer
我叫mt 第四季_网页搜索 - Microsoft Internet Explorer
狗狗搜索-我叫mt 第四季 - Microsoft Internet Explorer
我叫mt 第四季 - 必应 Bing - Microsoft Internet Explorer
我叫mt 第四季 - Google 搜索 - Microsoft Internet Explorer
我叫mt 第四季?-?搜狗搜索 - Microsoft Internet Explorer
我叫mt 第四季 - 有道搜索 - Microsoft Internet Explorer
我叫mt 第四季 - 搜搜更懂你 - Microsoft Internet Explorer
百度搜索_我叫mt 第四季 - Microsoft Internet Explorer
如上所示,假如打开了若干个网页窗口,不确定有多少个窗口,也不确定各窗口完整的标题是什么,只知道都含"Microsoft Internet Explorer"这个字符串。另外还有其它若干非浏览器窗口。
如何枚举出所有含"Microsoft Internet Explorer"这个关键词的窗口的句柄呢?
感觉是个简单问题,但是这两天被正则弄眯瞪了....有点卡壳
发表于 2016-11-13 01:59:56 | 显示全部楼层
WinList ( ["窗口标题" [, "窗口文本"]] )
若没有指定窗口标题及窗口文本则返回所有顶层窗口.

本函数返回的数组是一个二维数组,包含下列信息:
$array[0][0] = 窗口数 
$array[1][0] = 第1个窗口的标题 
$array[1][1] = 第1个窗口的句柄(HWND)
$array[2][0] = 第2个窗口的标题 
$array[2][1] = 第2个窗口的句柄(HWND) 
...
$array[n][0] = 第n个窗口的标题 
$array[n][1] = 第n个窗口的句柄(HWND) 
发表于 2016-11-13 04:07:53 | 显示全部楼层
本帖最后由 Huiseyu 于 2016-11-13 04:12 编辑

刚好我这有一个现成的,但是写的太乱,可读性很差.
都是基于下面的函数实现
$Get_WINALL = _WinAPI_EnumWindows() ;枚举
发表于 2016-11-13 05:09:59 | 显示全部楼层
楼主试试是不是这个
$winlist = winlist()

global $Str_WinTitle="Internet Explorer"

for $i = 1 to ubound($winlist) - 1

$title = $winlist[$i][0]

if stringinstr($title ,$Str_WinTitle) then

$text = '在标题'&$title &'中包含了' &$Str_WinTitle& @tab & '字符,它的句柄:'& $winlist[$i][1]

consolewrite($text&@crlf)

endif

next
 楼主| 发表于 2016-11-14 12:25:55 | 显示全部楼层
WinList ( ["窗口标题" [, "窗口文本"]] )
nmgwddj 发表于 2016-11-13 01:59

就是在想,用这个winlist+正则来达到目的呢
只是对AU3的正则不熟悉,不知道怎么弄出来......
 楼主| 发表于 2016-11-14 12:28:36 | 显示全部楼层
楼主试试是不是这个
Huiseyu 发表于 2016-11-13 05:09

嗯,用这个_WinAPI_EnumWindows也是一个办法,只是感觉有点复杂,跟自己再写一个函数差不多
 楼主| 发表于 2016-11-14 12:39:17 | 显示全部楼层
终于知道咋弄了......
local $lrr=WinList("[REGEXPTITLE:(?i)(.*Internet Explorer.*)]")
_ArrayDisplay($lrr,"lrr")

评分

参与人数 1金钱 +20 收起 理由
Huiseyu + 20 正则还能这样玩,厉害,多谢共享,学习...

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-19 09:34 , Processed in 0.088304 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表