Hi,

I have been using a Python script to launch various applications but have run into a problem when trying to build some resiliency into it. A second script i created waits and checks for a certain window title to take focus and then clicks on the OK button if it appears:

w=win32gui
foreground = w.GetForegroundWindow()
windowtext = w.GetWindowText(foreground)
if re.search('something',windowtext)
 code to click the OK button....

The problem is that I really need to search for the text in the message box window and not its title : the two are different and the error text contains a string I am looking for. However, "windowtext" only gets the message/error dialog box title.

Is there any way of finding the dialog box contents rather than title?

Cheers,

Matt

That's what GetWindowText is supposed to do
If you want to get the contents, you have to do something like this:

import win32gui as w

WM_GETTEXTLENGTH = 0x0E
WM_GETTEXT = 0x0D

t1 = w.SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0)  #hwnd has to be the handle to the text control
t = " "*t1
tl = w.SendMessage(hwnd, WM_GETTEXT, tl + 1, t)