5

特定の IE インスタンスの子を取得して、ポップアップがあるかどうかを確認したいと考えています。

ウィンドウをポップアップする .html ページを作成しました。このバージョンの IE では常にそうであるように、ポップアップのタイトルは「Web ページからのメッセージ」です。

子ウィンドウから親を取得できます。

>>> 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'

ただし、親から子ウィンドウを取得できないようです:

>>> def all_ok(hwnd, param): return True
>>> win32.EnumChildWindows(parent_handle, all_ok, None)
>>>

どうしてこれなの?

4

1 に答える 1

11

実際、ハンドラーは各子に対して呼び出されます。

>>> 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...

それ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]
>>>
于 2012-09-03T20:48:41.780 に答える