I have a C program that has a textbox component. I want to have a python GUI write text to this text box. Currently, I can write to the textbox HWND using:
def winFunc(hwnd, lparam):
s = win32gui.GetWindowText(hwnd)
if s == "":
win32gui.SendMessage(hwnd, win32con.WM_SETTEXT, 0, lparam)
hwnd = win32gui.FindWindow("Graph Program", None)
win32gui.EnumChildWindows(hwnd, winFunc, text)
This code will write text to the textbox but it cannot append text on a newline to the textbox. Is it possible to read in the text that is currently in the textbox or is it possible to add text to a textbox? I am new to using the windows API. Also, Is it possible to write text as a different color? The text box class is RICHEDIT20A.
Appending text
EM_SETSELmessage to move the selection to the end of the rich edit control. UseWM_GETTEXTLENGTHto find out how many characters are in the edit control.EM_REPLACESELmessage to replace the selection. If the selection point is at the end of the control, then replacing is the same as appending.Don’t attempt to use
WM_GETTEXT&WM_SETTEXTsince it rapidly becomes inefficient, not to mention the fact that the formatting is not preserved.Formatting text
Use the
EM_SETCHARFORMATto format text. More details over at MSDN.