Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Finding and closing a window based on its contents

Posted on 2004-10-29
Medium Priority
Last Modified: 2010-05-02
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.
Question by:LucDesaulniers
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 375 total points
ID: 12448434
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?

LVL 14

Expert Comment

ID: 12449520
Are you talking about windows from 1 kind of application ? Or can it be different applications ?
LVL 12

Accepted Solution

Bob Lamberson earned 375 total points
ID: 12450015

Author Comment

ID: 12462108
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.

LVL 12

Expert Comment

by:Bob Lamberson
ID: 12816125
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.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question