如何使用python和win32 api将颜色文本写入文本框? [英] How can I write color text to a textbox using python and the win32 api's?
问题描述
基本上我想使用python将彩色文本写入另一个应用程序的文本框窗口。
Basically I want to write colored text to a textbox window of another application using python.
一般的想法是:
win32gui.SendMessage( hwnd, EM_SETCHARFORMAT, SCF_SELECTION, format);
其中format是 CHARFORMAT 。
我的问题是EM_SETCHARFORMAT和SCF_SELECTION
My problem is that EM_SETCHARFORMAT and SCF_SELECTION are not included in the win32con library (I think) and I am unsure how to create a CHARFORMAT object.
在python中是否可能?
Is this possible in python?
推荐答案
事实证明,这是很难实现的。问题是 EM_SETCHARFORMAT
通过引用传递结构。 EM_SETCHARFORMAT
不是常见的Windows消息之一,它在 WM_USER
范围内。 lParam
指向的内存没有在进程边界之间编组。
It turns out that this is quite difficult to achieve. The problem is that the EM_SETCHARFORMAT
passes a structure by reference. The EM_SETCHARFORMAT
is not one of the common Windows messages, it's in the WM_USER
range. The memory pointed to by lParam
is not marshalled across the process boundary. The receiver of the message receives a pointer to memory that is only meaningful in the sender's process.
这意味着你唯一的解决方案是使用 WriteProcessMemory
将 CHARFORMAT
缓冲区写入目标进程中分配的内存块。这是可能的,但相当麻烦,尤其是在Python。
This means that your only solution will be to use WriteProcessMemory
to write the CHARFORMAT
buffer into a block of memory allocated in the target process. This is all possible but quite cumbersome, especially in Python.
如果我是你,我会考虑一个替代解决方案你的问题。
If I were you, I would consider an alternative solution to your problem.
这篇关于如何使用python和win32 api将颜色文本写入文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!