'getting text from notepad by control's hwnd
import win32gui
import time
while True:
window = win32gui.GetForegroundWindow()
title = win32gui.GetWindowText(window)
print(window)
if 'Notepad' in title:
control = win32gui.FindWindowEx(window, 0, 'Edit', None)
controldlgid = win32gui.GetDlgCtrlID(control)
print(controldlgid)
try:
mytext = win32gui.GetDlgItemText(window, controldlgid)
print(mytext)
except:
print('an error occured')
time.sleep(1)
I'd like to use win32gui.GetDlgItemText to get what is wrote on the activated notepad window and here's my code.
it's not working.:(
for detail, there's not error occured, but the variable named mytext is empty.
what did I do wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
