开发者

How can I write multiple lines to a textbox using python win32?

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)

Thi开发者_开发技巧s 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

  1. Send an EM_SETSEL message to move the selection to the end of the rich edit control. Use WM_GETTEXTLENGTH to find out how many characters are in the edit control.
  2. Send an EM_REPLACESEL message 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_SETTEXT since it rapidly becomes inefficient, not to mention the fact that the formatting is not preserved.

Formatting text

Use the EM_SETCHARFORMAT to format text. More details over at MSDN.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜