我几天前开始学习python并且在我试图从记事本中获取文本时卡住了
下面的代码返回窗口标题但是当我使用win32gui.GetWindowText(control)时它返回null。有人会在这里标出我的错误吗?提前谢谢
import time
import win32gui
while True:
window = win32gui.GetForegroundWindow()
title = win32gui.GetWindowText(window)
control = win32gui.FindWindowEx(window, 0, 'Edit', None)
print('text: ', win32gui.GetWindowText(window))
print('control to %s, window to %s' %(str(control), str(window)))
time.sleep(1)
答案 0 :(得分:2)
MSDN在documentation告诉您两次这不起作用!
GetWindowText无法检索另一个应用程序中控件的文本
要在另一个进程中检索控件的文本,请直接发送WM_GETTEXT消息,而不是调用GetWindowText。