nbsp; button1: tbutton;
button2: tbutton;
timer1: ttimer;
procedure formcreate(sender: tobject);
procedure button1click(sender: tobject);
procedure timer1timer(sender: tobject);
procedure button2click(sender: tobject);
private
{ private declarations }
public
{ public declarations }
end;
var
form1: tform1;
acttime1,acttime2:cardinal;
smmcount,stimercount,spcount:single;
htimeid:integer;
iten:integer;
protimecallback:tfntimecallback;
procedure timeproc(utimerid, umessage: uint; dwuser, dw1, dw2: dword) stdcall;
procedure proendcount;
implementation
{$r *.dfm}
//timesetevent的回调函数
procedure proendcount;
begin
acttime2:=gettickcount-acttime1;
form1.button2.enabled :=false;
form1.button1.enabled :=true;
form1.timer1.enabled :=false;
smmcount:=60;
stimercount:=60;
spcount:=-1;
timekillevent(htimeid);
end;
procedure timeproc(utimerid, umessage: uint;dwuser, dw1, dw2: dword) stdcall;
begin
form1.edit2.text:=floattostr(smmcount);
smmcount:=smmcount-0.01;
end;
procedure tform1.formcreate(sender: tobject);
begin
button1.caption :=''开始倒计时'';
button2.caption :=''结束倒计时'';
button2.enabled :=false;
button1.enabled :=true;
timer1.enabled :=false;
smmcount:=60;
stimercount:=60;
spcount:=60;
end;
procedure tform1.button1click(sender: tobject);
var
lgtick1,lgtick2,lgper:tlargeinteger;
ftemp:single;
begin
button2.enabled :=true;
button1.enabled :=false;
timer1.enabled :=true;
timer1.interval :=10;
protimecallback:=timeproc;
htimeid:=timesetevent(10,0,protimecallback,1,1);
acttime1:=gettickcount;
//获得系统的高性能频率计数器在一毫秒内的震动次数
queryperformancefrequency(lgper);
ftemp:=lgper/1000;
iten:=trunc(ftemp*10);
queryperformancecounter(lgtick1);
lgtick2:=lgtick1;
spcount:=60;
while spcount>0 do begin
queryperformancecounter(lgtick2);
//如果时钟震动次数超过10毫秒的次数则刷新edit3的显示
if lgtick2 - lgtick1 > iten then begin
lgtick1 := lgtick2;
spcount := spcount - 0.01;
edit3.text := floattostr(spcount);
&nb