2012-09-03 30 views
4

我想讓特定IE實例的子節點看看是否有彈出窗口。EnumChildWindows不能在pywin32中工作

我製作了一個彈出窗口的.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' 

然而,似乎我無法從母公司獲得的子窗口:

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

這是爲什麼?

+0

爲什麼「我似乎無法」 - >「看起來我不行」? – Claudiu

回答

8

處理程序確實要求每個孩子

>>> 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] 
>>> 
+0

在寫這個問題的過程中想到了這一點,認爲它可能會幫助其他人 – Claudiu

相關問題