?
Solved

wait until window is available

Posted on 2000-02-16
12
Medium Priority
?
175 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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