Finding and closing a window based on its contents

I know that you can close a window by using the SENDMESSAGE function but is there a way to find a window based on its contents and not by its title?

Let's say I have two windows on screen. One that contains the word "Hello to all human beings" and another that contains "Good morning to you". Is there a function that would allow me to find the first by searching with the word "beings"? I repeat, the words are NOT in the title bar but in the window itself.

Thank you.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Bob LambersonConnect With a Mentor Software EngineerCommented:
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
That really depends on how the words are being displayed.  If they are being rendered graphically then the answer is no (unless you resort to OCR techniques).  If they are in labels, then depending on the language the application was developed in, the answer is maybe.  If the text is in a standard control such as a textbox, then it is possible to enumerate all the windows in an app and query them for their text value using API calls.

Could you elaborate a little more on the type of apps these are and how the text you want to search for is displayed?

Are you talking about windows from 1 kind of application ? Or can it be different applications ?
LucDesaulniersAuthor Commented:
Thanks. I'll try that.
Just to clear things up, here is my exact situation.

My company is using a mission-critical system to publish invoices and uses Acrobat Distiller to convert them into PDF files. Problem is that Distiller cannot run as a service to whenever something is wrong with the file to be converted, a message will pop on screen and Distiller will wait for someone to click on the OK button to resume working. You can guess that this can cause big problems when that happens in the middle of the night.

Right now we have instructed the night shift operator to go and check on the server from time to time and click on the OK button should he see an error message on screen but that can lead to human error.

I first wrote a VB program to close a window based on its title but that won't do the trick because both Distiller and the error message box share the same title. So if I were to run my program both the error message and Distiller would end up being shut down which would only make the problem worse.

The error message box always contains the words "ERROR OPENING FILE...". So I would like to write a program that would search for windows containing these words and shut them down.

I will look at th supplied thread and let you know if it does the trick for me.

Bob LambersonSoftware EngineerCommented:
using API to enum all the windows and test for the contents is the answer and IM and I both provided that information. I think the points should be split.
All Courses

From novice to tech pro — start learning today.