熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

利用Delphi建立精確計數器[3]

2013-11-23 17:45:38  來源: Delphi編程 

  procedure TimeProc(uTimerID uMessage: UINT;

      dwUser dw dw: DWORD) stdcall;

  begin

    FormEditText:=FloatToStr(smmCount);

    smmCount:=smmCount;

  end;

  procedure TFormFormCreate(Sender: TObject);

  begin

    ButtonCaption :=´開始倒計時´;

    ButtonCaption :=´結束倒計時´;

    ButtonEnabled :=False;

    ButtonEnabled :=True;
  
    TimerEnabled :=False;

    smmCount:=;

    sTimerCount:=;

    sPCount:=;
  
  end;

  procedure TFormButtonClick(Sender: TObject);

  var

    lgTicklgTicklgPer:TLargeInteger;

    fTemp:Single;

  begin

  ButtonEnabled :=True;

  ButtonEnabled :=False;

  TimerEnabled :=True;

  TimerInterval :=;

  proTimeCallback:=TimeProc;

  hTimeID:=timeSetEvent(proTimeCallback);

  actTime:=GetTickCount;

 

  //獲得系統的高性能頻率計數器在一毫秒內的震動次數

  QueryPerformanceFrequency(lgPer);

  fTemp:=lgPer/;

  iTen:=Trunc(fTemp*);

  QueryPerformanceCounter(lgTick);

  lgTick:=lgTick;

  sPCount:=;

  while sPCount> do begin

    QueryPerformanceCounter(lgTick);

    //如果時鐘震動次數超過毫秒的次數則刷新Edit的顯示

    If lgTick lgTick > iTen Then begin

            lgTick := lgTick;

            sPCount := sPCount ;

            EditText := FloatToStr(sPCount);

            ApplicationProcessMessages;

      end;

    end;

  end;

 

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/Delphi/201311/25028.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.