多线程改变窗口标题
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) grp1: TGroupBox; edt1: TEdit; btn1: TButton; btn2: TButton; btn3: TButton; btn4: TButton; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); procedure btn3Click(Sender: TObject); procedure btn4Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; MyThreadID: DWORD ;//多线程ID MyThread: THandle; //多线程句柄 implementation {$R *.dfm} {多线程函数} procedure MyFunction();//线程要执行的函数 var i:integer; begin for i := 0 to 200000 do //循环改变窗口标题 Form1.Text := IntToStr(i); end; {开始} procedure TForm1.btn1Click(Sender: TObject); begin MyThread:=createthread(nil,0,@MyFunction,nil,0,MyThreadID); //创建线程并立即执行 if MyThread = 0 then ShowMessage('多线程创建失败'); end; {挂起} procedure TForm1.btn2Click(Sender: TObject); begin suspendthread(MyThread);//挂起线程 end; {继续} procedure TForm1.btn3Click(Sender: TObject); begin ResumeThread(MyThread);//恢复线程 end; {结束线程} procedure TForm1.btn4Click(Sender: TObject); begin TerminateThread(MyThread,2);//结束线程 end; end.