简体   繁体   English

如何从窗口获取文本?

[英]How can I get a text from a window?

Here my function: 这是我的功能:

def getEditText(hwnd):
    result = []
    bufferlength = struct.pack('i', 255)
    linecount = win32gui.SendMessage(hwnd, win32con.EM_GETLINECOUNT, 0, 0)
    print"--- linecount :",linecount

    for line in range(linecount):
        linetext = bufferlength + "".ljust(253)        
        linelength = win32gui.SendMessage(hwnd, win32con.EM_GETLINE, line, linetext)
 myLigne=linetext[:linelength] 
 print"  ",myLigne
        result.append(myLigne)
    return result
resultat=getEditText(hwmdTexte)

I want to get the text from a widget but this doesn't work. 我想从小部件中获取文本,但这不起作用。 There are several lines in the widget of my application but I have linecount=0 and of course no text... Could you please help me. 我的应用程序的小部件中有几行,但我的行数= 0,当然也没有文本……请帮助我。

Thanks for your answer. 感谢您的回答。 I've just tried def 我刚尝试过def

GetText(hwnd):
    buf_size = 1 + win32gui.SendMessage(hwnd, win32con.WM_GETTEXTLENGTH, 0, 0)
    buffer = win32gui.PyMakeBuffer(buf_size)
    win32gui.SendMessage(hwnd, win32con.WM_GETTEXT, buf_size, buffer)
    return buffer[:buf_size]    

But this doesn't get the text of my widget. 但这没有得到我的小部件的文本。 This function returns NUL... 该函数返回NUL ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM