delphi多线程进度显示问题
procedurea;begin...end;procedureTForm1.btn3Click(Sender:TObject);varI:integer;id:THan...
procedure a;
begin
...
end;
procedure TForm1.btn3Click(Sender: TObject);
var I:integer; id:THandle;
begin
for I := 0 to 10000 - 1 do
begin
CreateThread(nil, 0, @a, nil, 0, id);
end;
end;
//代码如上,请问如何在界面上的进度条中显示多程序的进度
//不能用timer控件 展开
begin
...
end;
procedure TForm1.btn3Click(Sender: TObject);
var I:integer; id:THandle;
begin
for I := 0 to 10000 - 1 do
begin
CreateThread(nil, 0, @a, nil, 0, id);
end;
end;
//代码如上,请问如何在界面上的进度条中显示多程序的进度
//不能用timer控件 展开
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Gauges;
const msg_update = WM_USER + 1;
type
TForm1 = class(TForm)
Gauge1: TGauge;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure update_msg(var msg:TMessage); message msg_update;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
type
TUpdateThread = class(TThread)
public
formHandle:THandle;
procedure Execute;override;
end;
procedure TForm1.update_msg(var msg: TMessage);
begin
if Gauge1.Progress >= 100 then
Gauge1.Progress := 0
else
Gauge1.Progress := Gauge1.Progress + msg.WParam;
end;
{ TUpdateThread }
procedure TUpdateThread.Execute;
begin
inherited;
while(not Terminated or Suspended) do
begin
Sleep(500);
PostMessage(formHandle,msg_update,1,0)
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
test:TUpdateThread;
begin
test := TUpdateThread.Create(True);
test.formHandle := self.Handle;
test.Resume;
Button1.Enabled := False;
end;
end.
通过句柄,发消息来处理即可。
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Gauges;
const msg_update = WM_USER + 1;
type
TForm1 = class(TForm)
Gauge1: TGauge;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure update_msg(var msg:TMessage); message msg_update;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
type
TUpdateThread = class(TThread)
public
formHandle:THandle;
procedure Execute;override;
end;
procedure TForm1.update_msg(var msg: TMessage);
begin
if Gauge1.Progress >= 100 then
Gauge1.Progress := 0
else
Gauge1.Progress := Gauge1.Progress + msg.WParam;
end;
{ TUpdateThread }
procedure TUpdateThread.Execute;
begin
inherited;
while(not Terminated or Suspended) do
begin
Sleep(500);
PostMessage(formHandle,msg_update,1,0)
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
test:TUpdateThread;
begin
test := TUpdateThread.Create(True);
test.formHandle := self.Handle;
test.Resume;
Button1.Enabled := False;
end;
end.
通过句柄,发消息来处理即可。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询