EnumChildWindows does not work in pywin32

I want the children of a particular instance of IE to see if there are pop-ups.

I created a .html page that opens a window. The title of the popup is “Webpage Message,” as is always done 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 looks like I cannot get the child window from the parent:

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

Why is this?

+4
source share
1 answer

The handler is actually 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 does not return anything. If you want to have all the child window handlers in the list, do this 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] >>> 
+8
source

Source: https://habr.com/ru/post/1432152/


All Articles