Solved

Finding and closing a window based on its contents

Posted on 2004-10-29
159 Views
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.
0
Question by:LucDesaulniers
    5 Comments
     
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    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?

    ~IM
    0
     
    LVL 14

    Expert Comment

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

    Accepted Solution

    by:
    0
     

    Author Comment

    by:LucDesaulniers
    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.

    Thanks.
    0
     
    LVL 12

    Expert Comment

    by:BobLamberson
    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.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Lean Six Sigma Project Manager Certification

    There are many schools of thought around successful project management, but few as highly regarded as the Six Sigma and Lean methods. With 37 hours of learning, this training will explain concrete processes for increasing efficiency and limiting wasted time and effort.

    Suggested Solutions

    Title # Comments Views Activity
    Pivot linking back to source data 2 38
    Problem to cells 11 55
    z = x + y – 1 6 44
    Window placement 17 45
    Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    877 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now