Using Python to send/receive text from GUI program
I'm using PyWin32's win32process.CreateProcess to start up a GUI program that has functionality I want to use in a Python class.
I want to do the following from Python with this GUI:
- sent text to individual windows withi开发者_运维技巧n the GUI (which seem to change identifiers every time I create the process if WinSpy++ is to be believed),
- click buttons on the GUI to configure and initiate the calculation, and
- retrieve calculation output from the GUI (which allows for either in-GUI text output or save-file output).
Quick question: what Python/PyWin32 functionality should I be researching to accomplish these tasks? I'm not looking for actual code, just the area I should research to learn how to do these things myself. I've scanned most of Learning Python, Programming Python, and Python Programming on Win32 and don't recognize the answer if it's there.
Thanks,
Mike
What you want to do is complicated and I'm not sure you can accomplish that with Python. I can only post some pointers, but can't guarantee that it's right direction.
As for sending text to individual windows - there is SendMessage function - you'd probably need to send your data as keystroke messages to desired window. As for hWnd
argument that SendMessage
takes - you should be able to obtain it by calling EnumChildWindows function or similar.
Retrieving output is even harder - I think you need to replace WndProc
of target window with one that will save output for you while it's being printed. You can substitute WndProc
with SetWindowLong (probably).
It should be possible that way, but personally I'd do anything to avoid coding something like that.
One more thing - it's not exactly python related question. Try to find C/C++ code accomplishing something similar with Win32API and try to translate it to Python. Search SO for WinAPI resources. If you're desperate enough, that is...
精彩评论