EnumChildWindows 在 pywin32 中不起作用 [英] EnumChildWindows not working in pywin32
问题描述
我想获取特定 IE 实例的子项,以查看是否有任何弹出窗口.
我制作了一个弹出窗口的 .html 页面.弹出窗口的标题是来自网页的消息",这个版本的 IE 总是如此.
我可以从子窗口获取父窗口:
<预><代码>>>>child_handle = 15208472>>>win32gui.GetWindowText(child_handle)'来自网页的消息'>>>win32gui.GetParent(child_handle)33230502>>>parent_handle = 33230502>>>win32gui.GetWindowText(parent_handle)'弹出示例 - Windows Internet Explorer'但是,我似乎无法从父窗口获取子窗口:
<预><代码>>>>def all_ok(hwnd, param): 返回真>>>win32.EnumChildWindows(parent_handle, all_ok, None)>>>这是为什么?
确实为每个孩子调用处理程序:
<预><代码>>>>def all_ok(hwnd, param):... 打印 hwnd...返回真...>>>win32gui.EnumChildWindows(parent_handle, all_ok, None)17630538129119408260536413143214356400114718889048526189420768523526#等等...只是 EnumChildWindows
本身不返回任何内容.如果您想在列表中包含所有子窗口句柄,请在处理程序中执行此操作:
I want to get the children of a particular IE instance to see if there are any popups.
I've made an .html page that pops up a window. The title of the popup is "Message from webpage", as it always is for this version of IE.
I can get the parent from the child window:
>>> child_handle = 15208472
>>> win32gui.GetWindowText(child_handle)
'Message from webpage'
>>> win32gui.GetParent(child_handle)
33230502
>>> parent_handle = 33230502
>>> win32gui.GetWindowText(parent_handle)
'pop-up example - Windows Internet Explorer'
However, it seems that i can't get the child window from the parent:
>>> def all_ok(hwnd, param): return True
>>> win32.EnumChildWindows(parent_handle, all_ok, None)
>>>
Why is this?
The handler is indeed called for each child:
>>> def all_ok(hwnd, param):
... print hwnd
... return True
...
>>> win32gui.EnumChildWindows(parent_handle, all_ok, None)
17630538
12911940
8260536
4131432
14356400
11471888
9048526
18942076
8523526
#etc...
It's just that EnumChildWindows
itself doesn't return anything. If you want to have all of the child window handles in a list, do that in the handler:
>>> parent_handle = 33230502
>>> child_handles = []
>>> def all_ok(hwnd, param):
... child_handles.append(hwnd)
...
>>> win32gui.EnumChildWindows(parent_handle, all_ok, None)
>>> child_handles
[17630538, 12911940, 8260536, 4131432, 14356400, 11471888, 9048526, 18942076, 8523526, 6951400, 5968556, 19203900, 4459544, 15208240, 9700614, 5769012, 11277176, 7409598, 10225510, 8392342, 19270296, 32377256, 7276984, 20449052, 8262502, 11734380, 14749460, 5310608, 3935978, 125374254, 8457268, 2621704, 24840652, 5706936, 35261636, 10357170, 5641372, 8260848, 6559366]
>>>
这篇关于EnumChildWindows 在 pywin32 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!