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的用法的更多相关文章

  1. Timer计时不准确的问题及解决方法

    在项目中,需要每隔20ms发送一个RTP数据包.一开始使用的是System.Windows.Forms下的Timer类,但是发现明显延迟了.用StopWatch测了一下,发现它的触发间隔居然不是20m ...

  2. VC++或QT下 高精度 多媒体定时器

    在VC编程中,用SetTimer可以定义一个定时器,到时间了,就响应OnTimer消息,但这种定时器精度太低了.如果需要精度更高一些的定时器(精 确到1ms),可以使用下面的高精度多媒体定时器进行代码 ...

  3. timeSetEvent()函数

    原文链接地址:http://www.cnblogs.com/kangwang1988/archive/2010/09/16/1827872.html 微软公司在其多媒体Windows中提供了精确定时器 ...

  4. timeSetEvent

    Header: Declared in Mmsystem.h; include Windows.h.Library: Use Winmm.lib. MSDN里定义的函数原型如下: MMRESULT t ...

  5. EditText 基本用法

    title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...

  6. jquery插件的用法之cookie 插件

    一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...

  7. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  8. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  9. python enumerate 用法

    A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...

随机推荐

  1. Memcached初体验及原理解说

    1.简单介绍 Memcached 是一个 高性能的 分布式 内存对象缓存系统,用于动态Web应用降低数据库负载,提升性能. 2.试用场景 1.变化频繁,具有不稳定性的数据 (比方用户在线状态.在线人数 ...

  2. STL之如何选择顺序容器

    一.顺序容器的分类 顺序容器:vector向量.list链表.deque双端队列: 优先级最高的是vector向量,它的速度比较快,优点最多: 在程序设计中,容器可以切换: #include < ...

  3. GitHub的问题

    出现failed to publish the branch, 转自:http://blog.csdn.net/cucmakeit/article/details/29407329 (windows系 ...

  4. PHP学习笔记3-逻辑运算符

    逻辑运算符图解: 逻辑且&&: <?php /** * Created by PhpStorm. * User: Administrator * Date: 2015/6/26 ...

  5. Best Component for Bitmap Image

    The best is to purchase ImageEn and use the latest version. Coz nothing compares to ImageEn.... But ...

  6. Swift实战-QQ在线音乐(第一版)

    //一.*项目准备 1.QQ音乐App 界面素材:(我使用PP助手,将QQ音乐App备份,解压ipa文件 即可得到里面的图片素材) 2.豆瓣电台接口:"http://douban.fm/j/ ...

  7. Android内存之VSS/RSS/PSS/USS

    Terms VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存) RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存) PSS - P ...

  8. Ibatis调用存储过程实现增删改以及分页查询

    1.Ibatis实现增删改操作很简单了,通常我是将某一模块的增删改功能写在一个存储过程里,通过一个标识符去区分执行增加还是修改抑或删除操作. statement: <!-- 存储过程:实现学生的 ...

  9. 【ant项目构建学习点滴】--(3)打包及运行jar文件

    <?xml version="1.0" encoding="UTF-8"?> <project default="compile&q ...

  10. the Meta-Object Compiler (moc)

    the Meta-Object Compiler (moc) 元对象编译器是处理Qt的C++扩展的程序. moc工具读取C++头文件,如果它找到一个或者多个类声明包含Q_OBJECT宏.它生为那些类成 ...