Board index » delphi » SetConsoleCtrlHandler

SetConsoleCtrlHandler

I wonder if anyone can please help me.

I am calling DOS programs from within my Delphi program, and I would like
to be able to
detect when a DOS program has ended. I would prefer to test this with some
kind of event
being triggered when the DOS progranm ends. I read about this
SETCONSOLECTRLHANDLER function, tried it, but I couldn't get it to work.
Has anyone else
tried this procedure and got it working?  If you have please tell me about
it.

Thanks

Firoz

 

Re:SetConsoleCtrlHandler


Quote
Firoz wrote:

> I wonder if anyone can please help me.

> I am calling DOS programs from within my Delphi program, and I would like
> to be able to
> detect when a DOS program has ended. I would prefer to test this with some
> kind of event
> being triggered when the DOS progranm ends. I read about this
> SETCONSOLECTRLHANDLER function, tried it, but I couldn't get it to work.
> Has anyone else
> tried this procedure and got it working?  If you have please tell me about
> it.

> Thanks

> Firoz

This will do what You want:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

procedure DoIt(progr, progrpath : string);

implementation

{$R *.DFM}

procedure DoIt(progr, progrpath : string);
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;

begin
 FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
 StartupInfo.cb := Sizeof(TStartupInfo);
 if CreateProcess(nil,
                  PChar(progr),           // App to launch
                  nil,                    // Security
                  nil,                    // Security
                  False,
                  NORMAL_PRIORITY_CLASS,  // Priorit?t
                  nil,                    // Environment
                  PChar(progrpath),       // Path
                  StartupInfo,
                  ProcessInfo) then begin
   WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
   CloseHandle(ProcessInfo.hProcess);
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 DoIt('calc.exe','c:\windows');                     // the Win95
calculator
 // close the calculator and watch the next:
 DoIt('command.com /cdir *.* >c:\test.txt','c:\');  // a DOS command,
creates
                                                    // a file in c:\
end;
end.

I suppose You have Win95 and use Delphi 32bit!
If You use Delphi 16bit You have to take
 i:=shellexecute(.............);
 ...
 ...
 while GetModuleUsage(i) > 0 do Application.Processmessages;

If You use Win NT You have to change the paths of the demo apps to
launch,
I think.

Pat

Other Threads