📄 killthread.pas
字号:
unit KillThread;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
ThreadHandle: THandle; // holds a handle to the thread
implementation
{$R *.DFM}
function ThreadFunction(Info: Pointer): Integer; stdcall
var
Count: Integer; // general loop counter
FormDC: HDC; // holds a handle to the form device context
CountStr: string; // holds a string representation of Count
begin
{retrieve a handle to the form's device context}
FormDC := GetDC(Form1.Handle);
{show something visual}
for Count := 1 to 10000 do begin
CountStr := IntToStr(Count);
TextOut(FormDC, 10, 10, Pchar(CountStr), Length(CountStr));
end;
{release the device context}
ReleaseDC(Form1.Handle, FormDC);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ThreadId: DWORD; // holds the thread identifier
ExitCode: DWORD; // holds the thread exit code
begin
{create and execute a thread}
ThreadHandle := CreateThread(nil, 0, @ThreadFunction, nil, 0, ThreadId);
if ThreadHandle = 0 then
ShowMessage('Thread not Started');
{pause for a very short period}
Sleep(50);
{discontinue the thread prematurely}
TerminateThread(ThreadHandle, 4);
{retrieve and display the thread's exit code}
GetExitCodeThread(ThreadHandle, ExitCode);
Label1.Caption := 'The Thread is Terminated with '+ IntToStr(ExitCode)+
' as the Exit Code';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -