WinAPI: QueryPerformanceCounter - 获取高性能定时器的当前值

//声明:
QueryPerformanceCounter(
  var lpPerformanceCount: TLargeInteger {获取定时器每秒的频率数; TLargeInteger = Int64}
): BOOL; {返回 False 表示调用失败, 或者是硬件不支持高性能定时器}

 
 
 
 
 

 

 
  

//一个有趣的示例: 判断你的鼠标点击速度; 我的最快记录是 151 毫米
var
  n1,n2,n,f: Int64;
  b: Boolean;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  n := 0;
  b := not b;
  if b then QueryPerformanceCounter(n1) else begin
    QueryPerformanceCounter(n2);
    n := n2 - n1;
  end;

  if n<>0 then
  begin
    QueryPerformanceFrequency(f);
    n := n*1000 div f;
    Text := IntToStr(n) + ' ms';
  end else Text := '等待第二下...';
end;

 
 
 
 
 

 

 
  

你可能感兴趣的:(WinAPI: QueryPerformanceCounter - 获取高性能定时器的当前值)