Solved

Win32 API question

Posted on 1998-09-05
7
229 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
Technology Partners: 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 50 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show Listview image from database (String field) 5 188
Delphi problems to abort a printjob 9 51
delphi popmenu non latine charcters 3 49
Posting a string with PostMessage 23 48
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 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