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. BCB6.0是垃圾的二十条理由

    我用的BCB6.0和windows2000 都是公司配的正版,我也有多年的开发经验. 1. IDE常常出现非法操作,有时重起动还会出错,须要重装BCB. 2. 自己主动完毕和智能提示功能超慢,慢到能够 ...

  2. 【数据库摘要】5_Sql_IN

    IN 操作符 IN 操作符同意您在 WHERE 子句中查找多个值. SQL IN 语法 SELECT column_name(s) FROM table_name WHERE column_name ...

  3. 在UITouch事件中画圆圈-iOS8 Swift基础教程

    这篇教程主要内容展示如何利用Core Graphics Framework画圆圈,当用户点击屏幕时随机生成不同大小的圆,这篇教程在Xcode6和iOS8下编译通过. 打开Xcode,新建项目选择Sin ...

  4. vs2013内置IISExpress相关问题

    问题描述,以前做的程序迁移到vs2013后出现500.22问题. HTTP 错误 500.22 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设 ...

  5. [Swust OJ 893]--Blocks

    题目链接:http://acm.swust.edu.cn/problem/893/ Time limit(ms): 1000 Memory limit(kb): 65535   Josh loves ...

  6. BZOJ 1925: [Sdoi2010]地精部落( dp )

    dp(i,j)表示1~i的排列中, 以1~j为开头且开头是下降的合法方案数 这种数列具有对称性, 即对于一个满足题意且开头是上升的n的排列{an}, 令bn = n-an+1, 那么{bn}就是一个满 ...

  7. Android 使用 array.xml

    //获取文件资源 TypedArray mainNavIcon = context.getResources().obtainTypedArray(R.array.mainNavIcon); //获取 ...

  8. ORACLE存储过程笔记3

    ORACLE存储过程笔记3 流程控制 1.条件   if expression thenpl/sql or sqlend if;   if expression thenpl/sql or sqlel ...

  9. Python 2.7 学习笔记 面向对象的编程

    python是一种面向对象的语言.本文介绍如何用python进行面向对象的编程. 首先我们说下对象和类,类是一种类型的定义,对象是类的实例. 一.内置对象类型(内置类) 其实我们前面已经大量用到了对象 ...

  10. 编写存储过程导出oracle表数据到多个文本文件

    1.测试表和数据: create table test(id )); begin .. loop insert into test values(k,'test'||k); end loop; end ...