terminate.pas

来自「Delphi Win32核心API参考光盘源码 本书包含了常用的Windows」· PAS 代码 · 共 61 行

PAS
61
字号
unit Terminate;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ProcessInfo: TProcessInformation;   // holds process information

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  StartUpInfo: TStartUpInfo;   // holds startup information
begin
  {initialize the startup information}
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  with StartupInfo do
  begin
    cb := SizeOf(TStartupInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := SW_SHOWNORMAL;
  end;

  {launch a process}
  CreateProcess('c:\Windows\calc.exe', nil, nil, nil, False,
      NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  ExitCode: DWORD;             // holds the process exit code
begin
  {terminate the process and retrieve the exit code}
  TerminateProcess(ProcessInfo.HProcess, 10);
  GetExitCodeProcess(ProcessInfo.HProcess, ExitCode);

  {display the exit code}
  Label1.Caption := 'The exit code is '+Inttostr(ExitCode);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?