谁有写过使用API函数代替定时器控件的功能(200分)

  • 主题发起人 主题发起人 jlcsx
  • 开始时间 开始时间
J

jlcsx

Unregistered / Unconfirmed
GUEST, unregistred user!
谁有写过使用API函数代替定时器控件的功能
 
看看定时器里面的功能<br>用的是API和消息<br>那出来不知道能不能满足你的要求<br>FWindowHandle := Classes.AllocateHWnd(WndProc);<br>首先你需要一个接受消息的句柄<br>procedure TTimer.WndProc(var Msg: TMessage);<br>begin<br> &nbsp;with Msg do<br> &nbsp; &nbsp;if Msg = WM_TIMER then<br> &nbsp; &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp;Timer;<br> &nbsp; &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp; &nbsp;Application.HandleException(Self);<br> &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);<br>end;<br>和一个处理消息的过程<br>WM_TIMER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= $0113;<br>来处理这个消息<br>function SetTimer(hWnd: HWND; nIDEvent, uElapse: UINT;<br> &nbsp;lpTimerFunc: TFNTimerProc): UINT; stdcall;<br>.<br>.<br>.<br>相关的API自己查查吧
 
procedure OneMilliSecondProc(uTimerID: UINT; uMsg: UINT; dwUser: DWORD; dw1:<br> &nbsp;DWORD; dw2: DWORD);<br>begin<br> &nbsp;Form1.Label1.Caption := IntToStr(timeGetTime);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;wTimerRes_1ms, wAccuracy: UINT;<br><br>begin<br> &nbsp;wTimerRes_1ms := 10;<br> &nbsp;wAccuracy := 0;<br> &nbsp;timeSetEvent(wTimerRes_1ms, wAccuracy,<br> &nbsp; &nbsp;@OneMilliSecondProc, //回调函数[/red]<br> &nbsp; &nbsp;1000, //用户自传送到回调函数的数据<br> &nbsp; &nbsp;TIME_PERIODIC);<br>end;
 
用GetTickCount 它的功能是获得系统自从启动到现在所经过的毫秒数,这样很精确
 
var<br> &nbsp;lTimerId:integer=0;<br><br> procedure timer(); <br> &nbsp; begin<br> &nbsp; &nbsp;//你的代码<br> &nbsp; end;<br><br>要先执行这句<br> lTimerId:=SetTimer(0,0,1000,@timer);//1000为一秒
 
多人接受答案了。
 
后退
顶部