使用Python从GUI程序发送/接收文本
我正在使用 PyWin32 的 win32process.CreateProcess 启动一个 GUI 程序,该程序具有我想在 Python 类中使用的功能。
我想使用此 GUI 从 Python 执行以下操作:
- 将文本发送到 GUI 中的各个窗口(如果相信 WinSpy++,每次创建进程时似乎都会更改标识符),
- 单击 GUI 上的按钮来配置和启动计算,并
- 从 GUI 检索计算输出(允许 GUI 内文本输出或保存文件输出)。
简单的问题:我应该研究哪些 Python/PyWin32 功能来完成这些任务?我不是在寻找实际的代码,只是在寻找我应该研究的领域以学习如何自己做这些事情。我已经浏览了《学习 Python》、《Python 编程》和《Win32 上的 Python 编程》的大部分内容,但不知道答案是否存在。
谢谢,
迈克
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 within 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想要做的事情很复杂,我不确定你是否可以用Python来完成它。我只能发表一些指示,但不能保证它是正确的方向。
至于向各个窗口发送文本 - 有 SendMessage 函数 - 您可能需要将数据作为击键消息发送到所需的窗口。至于
SendMessage
所采用的hWnd
参数 - 您应该能够通过调用 EnumChildWindows 函数或类似函数。检索输出更加困难 - 我认为您需要将目标窗口的 WndProc 替换为在打印时为您保存输出的窗口。您可以将
WndProc
替换为 SetWindowLong (可能)。应该可以这样,但就我个人而言,我会尽一切努力避免编写类似的代码。
另一件事 - 这不完全是与 python 相关的问题。尝试找到使用 Win32API 完成类似操作的 C/C++ 代码,并尝试将其转换为 Python。在 SO 中搜索 WinAPI 资源。如果你足够绝望的话,那就是……
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 thatSendMessage
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 substituteWndProc
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...