Cla*_*diu 4 python winapi pywin32
我想让一个特定的IE实例的孩子看看是否有任何弹出窗口.
我制作了一个弹出窗口的.html页面.弹出窗口的标题是"来自网页的消息",因为它始终适用于此版本的IE.
我可以从子窗口获取父级:
>>> 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'
Run Code Online (Sandbox Code Playgroud)
但是,似乎我无法从父级获取子窗口:
>>> def all_ok(hwnd, param): return True
>>> win32.EnumChildWindows(parent_handle, all_ok, None)
>>>
Run Code Online (Sandbox Code Playgroud)
为什么是这样?
确实为每个孩子调用了处理程序:
>>> 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...
Run Code Online (Sandbox Code Playgroud)
只是它EnumChildWindows本身不会返回任何东西.如果要在列表中包含所有子窗口句柄,请在处理程序中执行此操作:
>>> 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]
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3752 次 |
| 最近记录: |