Delphi倒計時,毫秒級別,獲得系統的高性能頻率計數器在一毫秒內的震動次數,如果時鐘震動次數超過10毫秒的次數則刷新edit3的顯示,顯示從開始記數到記數實際經過的時間:
001
unit
Unit1;
002
interface
003
uses
004
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
005
ExtCtrls, StdCtrls, mmsystem;
006
type
007
TForm1 =
class
(TForm)
008
Edit1: TEdit;
009
Edit2: TEdit;
010
Edit3: TEdit;
011
Button1: TButton;
012
Button2: TButton;
013
Timer1: TTimer;
014
Label1: TLabel;
015
Label2: TLabel;
016
Label3: TLabel;
017
procedure
FormCreate(Sender: TObject);
018
Button1Click(Sender: TObject);
019
Timer1Timer(Sender: TObject);
020
Button2Click(Sender: TObject);
021
private
022
{ Private declarations }
023
public
024
{ Public declarations }
025
end
;
026
var
027
Form1: TForm1;
028
acttime1,acttime2:
cardinal
029
smmcount,stimercount,spcount:
single
030
htimeid:
integer
031
iten:
032
protimecallback:tfntimecallback;
033
timeproc(utimerid, umessage: uint; dwuser, dw1, dw2: dWord) stdcall;
034
proendcount;
035
implementation
036
{$R *.DFM}
037
//timesetevent的回調函數
038
039
begin
040
acttime2:=gettickcount-acttime1;
041
form1
.
button2
enabled :=
false
042
button1
true
043
timer1
044
smmcount:=
60
045
stimercount:=
046
spcount:=-
1
047
timekillevent(htimeid);
048
049
050
051
edit2
text:=floattostr(smmcount);
052
smmcount:=smmcount-
0.01
053
054
TForm1
055
056
caption :=
'開始倒計時'
057
'結束倒計時'
058
059
060
061
062
063
spcount:=
064
065
066
067
lgtick1,lgtick2,lgper:tlargeinteger;
068
ftemp:
069
070
071
072
073
interval :=
10
074
protimecallback:=timeproc;
075
htimeid:=timesetevent(
,
0
,protimecallback,
);
076
acttime1:=gettickcount;
077
//獲得系統的高性能頻率計數器在一毫秒內的震動次數
078
queryperformancefrequency(lgper);
079
ftemp:=lgper/
1000
080
iten:=trunc(ftemp*
081
queryperformancecounter(lgtick1);
082
lgtick2:=lgtick1;
083
084
while
spcount>
do
085
086
queryperformancecounter(lgtick2);
087
//如果時鐘震動次數超過10毫秒的次數則刷新edit3的顯示
088
if
lgtick2 - lgtick1 > iten
then
089
090
lgtick1 := lgtick2;
091
spcount := spcount -
092
edit3
text := floattostr(spcount);
093
application
processmessages;
094
095
096
097
098
099
edit1
text := floattostr(stimercount);
100
stimercount:=stimercount-
101
102
103
104
105
//顯示從開始記數到記數實際經過的時間
106
showmessage(
'實際經過時間'
+inttostr(acttime2)+
'毫秒'
107
108
本例效果圖: 代碼文件:unit Unit1;inter
我通過做此例同時證實了 GDI+ 可以直接顯示
原文地址:http://bdn.borland.com
function CreateThread(
TMediaPlay中有一個Display屬性
{擦除}Canvas.MoveTo(x1, y1); C