⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getexitcodethreadu.pas

📁 Delphi Win32核心API参考光盘源码 本书包含了常用的Windows API函数
💻 PAS
字号:
unit GetExitCodeThreadU;

interface

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

type
  TForm1 = class(TForm)
    Button_CreateThread: TButton;
    Button_GetExitCode: TButton;
    procedure Button_CreateThreadClick(Sender: TObject);
    procedure Button_GetExitCodeClick(Sender: TObject);
  private
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ThreadHandle: Integer;

implementation

{$R *.DFM}

function ThreadFunction(Info: Pointer): Integer; StdCall
var
  Count: Integer;        // general loop counter
  FormDC: HDC;           // holds the form device context
  CountStr: string;      // holds a string representation of the counter
begin
  {retrieve the form device context}
  FormDC := GetDC(Form1.Handle);

  {display something visual}
  for Count := 1 to 1000 do
  begin
    CountStr := IntToStr(Count);
    TextOut(FormDC, 10, 10, Pchar(CountStr), Length(CountStr));
  end;

  {release the device context and exit the thread}
  ReleaseDC(Form1.Handle, FormDC);
  ExitThread(4);
end;

procedure TForm1.Button_CreateThreadClick(Sender: TObject);
var
  ThreadId: DWORD;       // holds the thread identifier
begin
  {create and execute a thread}
  ThreadHandle := CreateThread(nil, 0, @ThreadFunction, nil, 0, ThreadId);
  
  if (ThreadHandle = 0) then
    MessageBox(Handle, 'No Thread Created', nil, MB_OK);
end;

procedure TForm1.Button_GetExitCodeClick(Sender: TObject);
var
  ExitCode: DWORD;      // holds the thread exit code
begin
  {retrieve and display the thread's exit code}
  GetExitCodeThread(ThreadHandle, ExitCode);
  ShowMessage('The exit code is ' + IntToStr(ExitCode));
end;

end.

⌨️ 快捷键说明

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