Solved

wait until window is available

Posted on 2000-02-16
12
170 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

831 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