国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Delphi > 正文

Delphi實(shí)現(xiàn)毫秒級(jí)別的倒計(jì)時(shí)實(shí)例代碼

2020-01-31 20:51:23
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文以實(shí)例簡(jiǎn)述了Delphi實(shí)現(xiàn)毫秒級(jí)別倒計(jì)時(shí)的方法。一般來(lái)說(shuō)可以獲得系統(tǒng)的高性能頻率計(jì)數(shù)器在一毫秒內(nèi)的震動(dòng)次數(shù),如果時(shí)鐘震動(dòng)次數(shù)超過(guò)10毫秒的次數(shù)則刷新edit3的顯示,顯示從開始記數(shù)到記數(shù)實(shí)際經(jīng)過(guò)的時(shí)間,具體實(shí)現(xiàn)代碼如下:

unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, mmsystem;type TForm1 = class(TForm)  Edit1: TEdit;  Edit2: TEdit;  Edit3: TEdit;  Button1: TButton;  Button2: TButton;  Timer1: TTimer;  Label1: TLabel;  Label2: TLabel;  Label3: TLabel;  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的回調(diào)函數(shù)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 :='開始倒計(jì)時(shí)'; button2.caption :='結(jié)束倒計(jì)時(shí)'; 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; //獲得系統(tǒng)的高性能頻率計(jì)數(shù)器在一毫秒內(nèi)的震動(dòng)次數(shù) queryperformancefrequency(lgper); ftemp:=lgper/1000; iten:=trunc(ftemp*10); queryperformancecounter(lgtick1); lgtick2:=lgtick1; spcount:=60; while spcount>0 do begin  queryperformancecounter(lgtick2);  //如果時(shí)鐘震動(dòng)次數(shù)超過(guò)10毫秒的次數(shù)則刷新edit3的顯示  if lgtick2 - lgtick1 > iten then  begin   lgtick1 := lgtick2;   spcount := spcount - 0.01;   edit3.text := floattostr(spcount);   application.processmessages;  end; end;end;procedure TForm1.Timer1Timer(Sender: TObject);begin edit1.text := floattostr(stimercount); stimercount:=stimercount-0.01;end;procedure TForm1.Button2Click(Sender: TObject);begin proendcount; //顯示從開始記數(shù)到記數(shù)實(shí)際經(jīng)過(guò)的時(shí)間 showmessage('實(shí)際經(jīng)過(guò)時(shí)間'+inttostr(acttime2)+'毫秒');end;end.
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 满城县| 梨树县| 桂林市| 金平| 天镇县| 临潭县| 开化县| 辽中县| 满洲里市| 孟州市| 楚雄市| 石河子市| 榆林市| 凤冈县| 四川省| 泰安市| 望城县| 兴化市| 峨边| 东兴市| 大港区| 礼泉县| 东阿县| 江达县| 赫章县| 南川市| 阿克| 新乐市| 呈贡县| 固始县| 华安县| 宜昌市| 巴彦淖尔市| 东台市| 五寨县| 延川县| 中宁县| 连城县| 华宁县| 麦盖提县| 宁武县|