Reputation: 91
I've started learning python few days ago and stuck while I was trying to get text from notepad
the code below returning me Window title but when I'm using win32gui.GetWindowText(control) it returns null. Could someone mark my mistake here? Thank you in advance
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)
Upvotes: 2
Views: 755
Reputation: 101636
MSDN tells you twice in the documentation that this will not work!
GetWindowText cannot retrieve the text of a control in another application
To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead of calling GetWindowText.
Upvotes: 3