相关文章推荐
博学的山寨机  ·  Firebase C++ admob ...·  11 月前    · 
魁梧的拖把  ·  ModuleNotFoundError: ...·  1 年前    · 
强健的沙发  ·  [python] ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm using the following callback function to get all top level windows including their child windows:

def mycallback(hwnd, data):
    data[win32gui.GetClassName(hwnd)] = hwnd
    win32gui.EnumChildWindows(hwnd, mycallback, data)
    return True
mywindows = {}
win32gui.EnumWindows(mycallback, mywindows)

That piece of code returns a huge dictionary of window handles. One of those handles is 788292, which is Notepad++. Then I search for the children of Notepad++/788292 via win32gui.EnumChildWindows on a separate console. That is how I notice the window handle 853784 whose name is "Edit".

However that window handle does not appear in my huge dictionary mentioned earlier. Why not?

Is the window handle specific to "EDIT" not listed? I use C++ to test these two functions by enumerating all the windows and enumerating all the child windows of "Notepad++" separately. Compare the child windows of "Notepad++", which return the same number of child windows. – Strive Sun Oct 3, 2019 at 3:30 By the way, I am testing your code in python and will return pywintypes.error: (126, 'EnumChildWindows', 'The specified module could not be found.'). I am still researching the specific cause of the error. This is why I switched to C++ testing. – Strive Sun Oct 3, 2019 at 3:32 I've retested the issue. This time it's a little bit different but in principle the same. This is the Notepad++/EnumChildWindows dictionary on a separate console (same callback as above): {'#32770': 66908, 'Button': 66922, 'Static': 66924, 'SysTabControl32': 132272, 'Scintilla': 132276, 'splitterContainer': 263444, 'wespliter': 328982, 'msctls_statusbar32': 394476, 'dockingManager': 394474, 'wedockspliter': 132328, 'nsdockspliter': 132336, 'ReBarWindow32': 66906, 'ToolbarWindow32': 66902, 'Edit': 66914}. Some of these windows are not contained in "mywindows"/EnumWindows, e.g. 66908, 66922... – Robert Oct 4, 2019 at 7:55 ohhh I have found the reason: there are MULTIPLE windows which return the same win32gui.GetClassName value :-) Hence some windows are overwritten in the dictionary. How embarassing, I should have noticed that, since it's "getCLASSname" ... sorry. I've just noticed it, because my Notepad++ Edit window had disappeared after I had started windows-notepad (which also has an Edit window) – Robert Oct 4, 2019 at 8:10

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.