1

I'm trying to import/extract the values of a form from another application to use in my code using python and pywin32.

With Spy++ I figured out the handles of the elements that I need to target, but I can't figure out how to obtain the text from the elements.

The way the target application is structured:

top app level
    (no name) class: MDIClient        (this is the centerWidget)
    (no name) class: ThunderRT6FormDC (occupies same space as centerwidget)
    (Ticket) class: ThunderRT6Frame  (Frame that holds all fields to extract from)
        (no name) class: NumEdit/DateEdit/TextEdit... (fields to import)
    (Information) class ThunderRT6Frame  (2nd frame with fields)
        (no name) class: NumEdit/DateEdit/TextEdit... (fields to import)
    (Process) class ThunderRT6Frame  (3rd frame with fields)
        (no name) class: NumEdit/DateEdit/TextEdit... (fields to import)
f = win32gui.FindWindow('ThunderRT6MDIForm', 'ApplicationName')
ex = win32gui.FindWindowEx(f, 0, 'MDIClient', None)
exx = win32gui.FindWindowEx(ex, 0, 'ThunderRT6FormDC', None)
exxx = win32gui.FindWindowEx(exx, 0, 'ThunderRT6Frame', None)
exxxx = win32gui.FindWindowEx(exxx, 0, 'NumEdit', None)

exxxx is the handle/element from which I want to extract the caption/text. I'm sure FindWindowEx isn't the right function as it searches for Windows, but what function do I have to use?

Dutchman
  • 67
  • 10

1 Answers1

0

[MS.Docs]: FindWindowExW function (wrapped by win32gui.FindWindowEx) should do the trick, if the relationship between 2 "consecutive" windows in the tree (e.g. ex and exx) is a parent - child one.

One other way would be to use [MS.Docs]: EnumChildWindows function (win32gui.EnumChildWindows) - also check EnumWindows.
For more details, you could take a look at:

From there, you can use GetWindowTextW (win32gui.GetWindowTextW) to get the caption for the desired window.

CristiFati
  • 38,250
  • 9
  • 50
  • 87