Solved

wait until window is available

Posted on 2000-02-16
12
166 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

23 Experts available now in Live!

Get 1:1 Help Now