现在的位置: 首页 > 综合 > 正文

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

2011年02月09日 ⁄ 综合 ⁄ 共 501字 ⁄ 字号 评论关闭
//声明:
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 n0 then begin QueryPerformanceFrequency(f); n := n*1000 div f; Text := IntToStr(n) + ' ms'; end else Text := '等待第二下...'; end;
【上篇】
【下篇】

抱歉!评论已关闭.