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

x
?
Solved

wait until window is available

Posted on 2000-02-16
12
Medium Priority
?
177 Views
Last Modified: 2010-04-04
Hello all!!!

i like to program , function that check until "window will appear" or will be available. let's say i start my program and my program will wait until window is found e.g "Untitled - Notepad" if notepad window is available i do some task, this have to work in Win2000.

A+ more points for good answer

Many Thanks
0
Comment
Question by:esk
[X]
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
  • 6
  • 5
12 Comments
 
LVL 6

Expert Comment

by:Jaymol
ID: 2527299
Here you go....

procedure WaitTillWindowIsAvailable(sTitle: String);
begin
  While FindWindow(nil, PChar(sTitle))=0 do
    Application.ProcessMessages;
end;


Then, after executing Notepad, all you do is .....

  WaitTillWindowIsAvailable('Untitled - Notepad');

Will that do you?

John.
0
 

Expert Comment

by:BSamson
ID: 2527324
I'm having to make a few assumptions here.

Firstly, I'm assuming that the window you're waiting for is a process that you've created yourself. i.e. you've started Notepad

I'm also assuming that it's not really that fact that the application is just visible that you're really interested in, but rather that it is up and running and waiting for a user to do something with it.

The function I've used for this purpose is :-

WaitForInputIdle( ProcessInfo.hProcess, 10000 );

If you've created the Process yourself then you'll already have the ProcessInfo record.

You should be conscious of not locking up the message quite with you're wait timeout.

If it fits with your application, you should Create the Process and Wait for the Idle from a different Thread.

Or decrease the Wait for Idle timeout to something much smaller than 10 seconds.

Brian
0
 
LVL 6

Accepted Solution

by:
Jaymol earned 1200 total points
ID: 2527326
Sorry....meant to put that as an answer.

John.
0
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!

 
LVL 6

Expert Comment

by:Jaymol
ID: 2527390
Esk : I've done this kind of thing before in the form of an email link that says "Contact the author" on about boxes in my software.  All (or most of) the PC's in the company I work for use Lotus Notes so I wrote a component that when clicked opens Lotus Notes, waits for the user to enter their password (if asked for it) and then creates a blank email to me and puts the cursor in the body.  So, if you need any more help with anything like this, just ask away and I can email you some code.

John.
0
 

Author Comment

by:esk
ID: 2527561
you may email me thanks

esk10000@hotmail.com
0
 

Author Comment

by:esk
ID: 2527572
This is my function

Procedure TMacroFunctions.CallUntilWindowAppear(WindowName : String; Time : Integer; Check : Boolean);
Var H      : THandle;
    Param1 : String;
    Param2 : Integer;
begin
If Check = True Then
Begin
Param1 := WindowName;
Param2 := Time;
H := FindWindow(NIL,ToPchar(WindowName));
Delay(Time);
While H > 0 Do
Begin
Exit;
End;
CallUntilWindowAppear(Param1,Param2,Check);
End;
End;

Any help?

i just want my program to freeze until it finds given window
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2527595
Just use the function I posted earlier and see what you think.  I'll send you something to play with so you can see how it works.

Check your email in a few minutes.

John.
0
 

Author Comment

by:esk
ID: 2527956
The CPU load is 100%, but the demo works

Esk
0
 

Author Comment

by:esk
ID: 2527966
Can you fix the CPU load?
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2527968
Yeah, the load is a bit false actually....all your program is doing is checking for the existence of the other app and then passing control to the OS.  This loop makes it appear that the CPU is well loaded, but it's not really.  If more stuff if running, your program will just check less regularly.  That's all.

John.
0
 

Author Comment

by:esk
ID: 2528021
Can you fix the CPU load?
0
 

Author Comment

by:esk
ID: 2528549
Adjusted points to 300
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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