timesetevent与timekillevent的用法
unit Unit1;
interface
uses
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的回调函数
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);
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;
//显示从开始记数到记数实际经过的时间
showmessage('实际经过时间'+inttostr(acttime2)+'毫秒');
end;
end.
http://blog.csdn.net/diligentcatrich/article/details/7008271
timesetevent与timekillevent的用法的更多相关文章
- Timer计时不准确的问题及解决方法
在项目中,需要每隔20ms发送一个RTP数据包.一开始使用的是System.Windows.Forms下的Timer类,但是发现明显延迟了.用StopWatch测了一下,发现它的触发间隔居然不是20m ...
- VC++或QT下 高精度 多媒体定时器
在VC编程中,用SetTimer可以定义一个定时器,到时间了,就响应OnTimer消息,但这种定时器精度太低了.如果需要精度更高一些的定时器(精 确到1ms),可以使用下面的高精度多媒体定时器进行代码 ...
- timeSetEvent()函数
原文链接地址:http://www.cnblogs.com/kangwang1988/archive/2010/09/16/1827872.html 微软公司在其多媒体Windows中提供了精确定时器 ...
- timeSetEvent
Header: Declared in Mmsystem.h; include Windows.h.Library: Use Winmm.lib. MSDN里定义的函数原型如下: MMRESULT t ...
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- python enumerate 用法
A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...
随机推荐
- C语言中没有main函数生成可执行程序的几种方法
1.define预处理指令 这种方式很简单,只是简单地将main字符串用宏来代替,或者使用##拼接字符串.示例程序如下: #include <stdio.h> #define begin ...
- 2013 成都网络赛 1004 Minimum palindrome
题目大意:用m个字母组成一个长度为N的字符串,使得最长的回文子串 的长度最小. 并且要求字典序最小. 思路:分类模拟. 当M为1 的时候就直接输出N个A 当M大于2的时候就循环ABC 当M等于2的时候 ...
- 你会用swift创建复杂的加载动画吗(1)
时至今日,iOS 应用商店已经拥有超过了140万 应用,让你自己的应用脱颖而出确实是个不小的挑战.不过,在你的应用掉入默默无闻的大黑洞之前,你拥有一个小小的机遇窗,它能帮你吸引用户的注意. AD: 时 ...
- win7 ShuipFCMS 配置 及问题
随风下载地址:http://www.shuipfcms.com/download.shtml 碰到问题: 一.mb_strlen 函数不支持 到php.ini 开启 ;extension=php ...
- php 学习笔记 数组2
10.切割数组 array_slice(array, offset, length);返回一个由原始数组中的连续元素组成的新数组,参数1为原始数组,参数2为要复制的起始位置, 参数3要复制的个数:新数 ...
- WIN7 数据源配置问题(32位&&64位)
WIN7-32位 配置数据源地址: C:\Windows\System32\odbcad32.exe WIN7-64位 配置数据源地址: C:\Windows\SysWOW64\ odbcad32.e ...
- Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】
一开始不知道题意是啥意思,迟放进去反应和后放进去反应有什么区别 对于第三组数据不是很懂,为啥312,132的组合是不行的 后来发现这是一道考察并查集的题目 QAQ 怒贴代码: #include < ...
- 转:Linus:利用二级指针删除单向链表
感谢网友full_of_bull投递此文(注:此文最初发表在这个这里,我对原文后半段修改了许多,并加入了插图) Linus大婶在slashdot上回答一些编程爱好者的提问,其中一个人问他什么样的代码是 ...
- 设计模式(九)外观模式Facade(结构型)
设计模式(九)外观模式Facade(结构型) 1. 概述 外观模式,我们通过外观的包装,使应用程序只能看到外观对象,而不会看到具体的细节对象,这样无疑会降低应用程序的复杂度,并且提高了程序的可维护性. ...
- NGUI出现Shader wants normals, but the mesh UIAtlas doesn't have them
NGUI出现Shader wants normals, but the mesh UIAtlas doesn't have them,没有网格法线,打开UI Root上 UIPanel组建上的 Nor ...