- 按键精灵会员
- 9151062
- 112
- 0
- 128 朵
- 248 个
- 173 个
- 0
- 2023-11-08
|
1#
t
T
发表于 2024-07-22 17:37
|
|只看楼主
- Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
- Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
- Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
- Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
- Call 遍历所有子句柄(GetForegroundWindow())
- Function 遍历所有子句柄(Hwnd)
- Dim i, HwndIE
- '用循环和栈代替递归:
- 栈_数组 = Array() : i = -1 : HwndIE = 0
- Do
- HwndIE = FindWindowEx(Hwnd, HwndIE, vbNullString, vbNullString)
- If HwndIE > 0 Then
- sClass = Space(50)
- GetClassName HwndIE, sClass, Len(sClass) : sClass = Left(sClass, Len(Trim(sClass)) - 1)
- sText = Space(255)
- GetWindowText HwndIE, sText, Len(sText) : sText = Left(sText, Len(Trim(sText)) - 1)
- TracePrint HwndIE & "|" & sClass & "|" & sText
- '------[入栈]------
- i = i + 1 : Redim Preserve 栈_数组(i) : 栈_数组(i) = Array(Hwnd, HwndIE)
- Hwnd = HwndIE : HwndIE = 0
- Else
- If i = -1 Then Exit Do
- '------[出栈]------
- Hwnd = 栈_数组(i)(0) : HwndIE = 栈_数组(i)(1) : i = i - 1
- End If
- Loop
- 栈_数组 = ""
- End Function
复制代码在论坛找的这些代码 紫猫写的 我想把他放到命令库里 ,在脚本中可以正常运行,但是放到命令库里就会出错 不知道是什么原因 以下是报错信息 脚本 遍历所有子句柄.Q ,第7行:类型不匹配: 'GETFOREGROUNDWINDOW',命令库 命令库.QML ,第28行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第28行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第30行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第31行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第41行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第43行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第43行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第43行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第30行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',命令库 命令库.QML ,第31行:缺少对象: 'F2730835_2229_445E_97C7_l3F7612771DA',
|