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 ...
随机推荐
- BZOJ 3155: Preprefix sum( 线段树 )
刷刷水题... 前缀和的前缀和...显然树状数组可以写...然而我不会, 只能写线段树了 把改变成加, 然后线段树维护前缀和, 某点p加, 会影响前缀和pre(x)(p≤x≤n), 对[p, n]这段 ...
- 随手记今天跟的几个iOS项目代码的问题
休了一阵子假期,今天刚回来上班,项目代码已经有挺大的变化了,我就先体验.发现.跟进问题. 第一个问题是点击某个cell就挂掉的现象,同事表示必现但挺神奇.由于挂掉的时候没有啥有意义的信息,所以先简单粗 ...
- [转] Chrome 控制台不完全指南
转自: http://www.cnblogs.com/Wayou/p/chrome-console-tips-and-tricks.html#home Chrome的开发者工具已经强大到没朋友的地步了 ...
- 我的Python成长之路---第四天---Python基础(14)---2016年1月23日(寒风刺骨)
一.生成器和迭代器 1.迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,不过这也没什么,因为人们很少在迭代途中往后退. ...
- 微信平台接入Web页面功能接口(C#)
微信平台接入web页面功能接口 今年因工作需要,通过微信平台接入公司的Wap页面,回忆下,记录内容,方面以后使用. 1.成为开发者后,你才可以使用公众平台的开发功能.需要填写URL和ToKen,接口配 ...
- Failed to retrieve procctx from ht. constr
给一个客户巡检时发生这样的少见的集群报错: [ OCRSRV][1220598112]th_select_handler: Failed to retrieve procctx from ht. c ...
- Poj 2777 Count Color(线段树基础)
又毁三观了.......虽然题目数据有坑:区间[a,b]可能会有a>b的情况,但是我一开始没有考虑它也能过. 此外莫名其妙的TLE #include <iostream> #incl ...
- Android跟蓝牙耳机建立连接有两种方式
Android 跟蓝牙耳机建立连接有两种方式. 1. Android 主动跟蓝牙耳机连BluetoothSettings 中和蓝牙耳机配对上之后, BluetoothHeadsetService 会收 ...
- Eclipse中JBOSS5.1无法启动的问题解决办法
今天在Eclipse中启动JBoss 5.1时遇到这样的一个错误: …… ERROR [AbstractKernelController] Error installing to Instantiat ...
- 【转】windows 7系统安装与配置Tomcat服务器环境
原文链接: windows 7系统安装与配置Tomcat服务器环境 工具/原料 jdk-8u51-windows-x64(我的系统是64位系统,32位的请选x86下载)下载地址:http://www. ...