Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EnumChildWindows not working in pywin32

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?

like image 792
Claudiu Avatar asked Sep 03 '12 20:09

Claudiu


1 Answers

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]
>>>
like image 132
Claudiu Avatar answered Sep 30 '22 14:09

Claudiu