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. CoreAnimation (CALayer 动画)

    CoreAnimation基本介绍: CoreAnimation动画位于iOS框架的Media层 CoreAnimation动画实现需要添加QuartzCore.Framework CoreAnima ...

  2. layout_weight属性详解

    看到上面这段代码,大家肯定认为三个TextView的宽度是1:2:2,但实际上是如图1这样的,宽度之比确实是1:2:2,但为什么第一个和后两个是齐平的呢?下面我给大家画一条线,可以看到虽然控件是没有对 ...

  3. c++,虚函数

    1.在声明函数时,在最前加上virtual,则该函数就是函虚数,基类的虚函数被派生类继承后仍是虚函数.2.派生类中可以重写基类的虚函数.3.用指针访问重写的虚函数时,被访问的虚函数是指针指向的对象所属 ...

  4. HDU 4891

    一道简单的模拟题 需要要匹配{} 和 $$ 符里面的东西即可 //#pragma comment(linker, "/STACK:16777216") //for c++ Comp ...

  5. Raphael入门实例:动画与箭头

    raphael 实例 动画 隐藏和显示参数说明 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 var c = paper.circle(50, 50, 40);   function ...

  6. 窗体区域绘制问题WS_CLIPCHILDREN与WS_CLIPSIBLINGS

    WS_CLIPCHILDREN,使得父窗体在绘制时留出其上的子窗体的位置不去画它,而那片区域留着子窗体去画.WS_CLIPSIBLINGS,必须用于子窗体,使得该子窗体在收到WM_PAINT时同时令其 ...

  7. jquery删除动态增加的li

    <script type="text/jscript"> //楼主帮你修改调整了下 $(document).ready(function () { $('.zuo li ...

  8. 流行的Python项目汇总

    年有哪些流行的Python项目呢?下面,我们一起来看下. 一.测试和调试 python_koans :Python Koans 算 “Ruby Koans” 的一部分,作为交互式教程,可以学习 TDD ...

  9. 基于visual Studio2013解决算法导论之047赫夫曼编码

     题目 赫夫曼编码 解决代码及点评 // 赫夫曼编码.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <stdio.h ...

  10. INS-30001 ADMIN口令为空

    1.错误描写叙述 2.错误原因 管理口令为空.导致出错 3.解决的方法 填写管理口令和确认口令