Solved

wait until window is available

Posted on 2000-02-16
12
173 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 300 total points
ID: 2527326
Sorry....meant to put that as an answer.

John.
0
Industry Leaders: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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