添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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 am using python 3.11 to achieve some windows ui automation using win32gui. The objective is to progrmatically find a TARGET child object inside a WINDOW NAME parent window, both name known and will not change. So far I cannot figure out how to access anything inside the parent window's tree and this is the only thing (that barely) worked:

hwnd = win32gui.FindWindow(None, 'WINDOW NAME')  # parent window
child_hwnd = win32gui.FindWindowEx(hwnd, 0, None, 'TARGET')  # target object
window_text = win32gui.GetWindowText(child_hwnd)  # extract window text

hwnd returns the handle of the parent window as int, child_hwnd returns 0, window text returns empty string. Although it does not provide any useful information it means that I am able to locate and get the handle of the parent window. The problem is probably that my TARGET is not a window but a list object.

I have checked the TARGET object I want to get using the inspector app from WindowsKit: it is a list object inside a pane object inside a pane object ... inside a window: screenshot of inspector of TARGET and its ancestors screenshot of inspector of TARGET in WINDOW NAME's tree

I have also tried EnumChildWindows but it says first param must be a callable object even I input the hwnd.

My objectives are to: 1.let Python send a query to the WINDOW NAME parent window, 2.get the window and search all its children (any filtering method will work) to find the TARGET, 3.get the TARGET list object (as bytes, strings, anything writeable).

I also tried searching for win32gui automation, but I do not know what keywords to search for so it keeps giving answers missing my point. Any ideas how to achieve the objective or suggestions what I should search for?

Everything in that display is a window. GDI does not have the concept of a "list object". I don't know that tool, but it may be that "list" is the window class. If so, you can pass that as the third parameter to FindWindowEx. Alternatively, you can use the almost always valid assumption that the child windows will be created in the same order, and grab the first child window. – Tim Roberts Aug 23 at 0:11 win32gui.EnumChildWindows takes three parameters: a window handle, a callable (which will be called once for each child window), and an optional context parameter to pass to the callback. timgolden.me.uk/pywin32-docs/… – Tim Roberts Aug 23 at 0:15 Appreciate your suggestions. I do not expect list to be the window class because the inspector says its ClassName is TXGuiFoundation, in fact, every object (or window) in that parent window has the same ClassName. The LocalizedControlType of the parent window is window while that for the target object is list. – Teddy Wei Aug 23 at 5:30 Another key question is that when I search through a window's children, do I search its grandchildren? As you may see in the screenshot my target is hidden inside layers and layers of structure, I am not sure if it is even reached in the search. – Teddy Wei Aug 23 at 5:36 You ought to be able to compare the list you see with the app. You will probably have to search recursively. – Tim Roberts Aug 23 at 6:13

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.