?
Solved

Win32 API question

Posted on 1998-09-05
7
Medium Priority
?
232 Views
Last Modified: 2010-04-06
I have the handle of an application running outside of my delphi 3.0 application. How can I check when that application is finished from inside of my delphi application?
0
Comment
Question by:fh1
[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
  • 5
  • 2
7 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1338755
There are many methods to do that and here is one of them,,,,,

In OnTimer()
var
  H : HWND;
begin
  H := FindWindow(nil, 'Untitled - Notepad');
  if H = 0 then
  begin
    ShowMessage('The application has already finished!');
    //Do your code here.....
    Timer1.Enabled := False;//If it's only for once..otherwise don't disable the timer...
  end;
end;

Regards,
Viktor Ivanov

0
 

Author Comment

by:fh1
ID: 1338756
To Viktor Ivanov:
I don't have the name of the window, but I have the handle of it.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338757
Here is the second method and more official, with a little more code....
Params -
   Filename - the filename of the app to execute and wait for.....
    Visibility - SW_SHOW, SW_HIDE, SW_SHOWNORMAL........
--------------
How do I execute a program and have my code wait until it is finished?

function WinExecAndWait32(FileName:String; Visibility : integer):integer;
var
  zAppName:array[0..512] of char;
  zCurDir:array[0..255] of char;
  WorkDir:String;
  StartupInfo:TStartupInfo;
  ProcessInfo:TProcessInformation;
begin
  StrPCopy(zAppName,FileName);
  GetDir(0,WorkDir);
  StrPCopy(zCurDir,WorkDir);
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);

  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName,                      { pointer to command line string }
    nil,                           { pointer to process security attributes }
    nil,                           { pointer to thread security attributes }
    false,                         { handle inheritance flag }
    CREATE_NEW_CONSOLE or          { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil,                           { pointer to new environment block }
    nil,                           { pointer to current directory name }
    StartupInfo,                   { pointer to STARTUPINFO }
    ProcessInfo) then Result := -1 { pointer to PROCESS_INF }

  else begin
    WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess,Result);
  end;
end;
------------
Regards,
Viktor Ivanov
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 10

Expert Comment

by:viktornet
ID: 1338758
If you want use the method I just gave otherwise if you want to use the first method here is how if you have the handle.....

var
  H : HWND;
begin
  H := //the handle you already know of your application.....
  if H = 0 then
  begin
    ShowMessage('The app is already running');
    //Do you job here.....
  end;
end;
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338759
oopssss....see the line that says ShowMessage('The app is already running');...this is suppose to be ShowMessage('The app is already finished');
sorry for the wrong code ;)

Regards,
Viktor Ivanov
0
 

Author Comment

by:fh1
ID: 1338760
Since I only know the handle of the window, I have to find the name of the window and then check in a loop if the handle of this window become zero.
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1338761
That's not true...You don't need the name if you know the handle. Just use the method I told you and that's all...

Regards,
Viktor Ivanov
0

Featured Post

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!

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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

719 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