如何用aip函数实现一个timer的功能呢?(100分)

  • 主题发起人 主题发起人 super110man
  • 开始时间 开始时间
S

super110man

Unregistered / Unconfirmed
GUEST, unregistred user!
想完成一个功能,但程序没有窗体,是用aip函数建的,想实现timer的功能,望高手指点,谢谢。
 
如果有TApplication的话,应该可以使用 SetTimer(). hWnd用Application的Handle试试。<br><br><br>SetTimer<br>The SetTimer function creates a timer with the specified time-out value. <br><br>UINT SetTimer(<br>&nbsp; HWND hWnd, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// handle of window for timer messages<br>&nbsp; UINT nIDEvent, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// timer identifier<br>&nbsp; UINT uElapse, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // time-out value<br>&nbsp; TIMERPROC lpTimerFunc &nbsp; // address of timer procedure<br>);<br>&nbsp;<br>Parameters<br>hWnd <br>Handle to the window to be associated with the timer. This window must be owned by the calling thread. If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored. <br>nIDEvent <br>Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. <br>uElapse <br>Specifies the time-out value, in milliseconds. <br>lpTimerFunc <br>Pointer to the function to be notified when the time-out value elapses. For more information about the function, see TimerProc. <br>If lpTimerFunc is NULL, the system posts a WM_TIMER message to the application queue. The hwnd member of the message'sMSG structure contains the value of the hWnd parameter. <br><br>Return Values<br>If the function succeeds, the return value is an integer identifying the new timer. An application can pass this value, or the string identifier, if it exists, to the KillTimer function to destroy the timer. <br><br>If the function fails to create a timer, the return value is zero. To get extended error information, call GetLastError.<br><br>Remarks<br>An application can process WM_TIMER messages by including a WM_TIMER case statement in the window procedure or by specifying a TimerProc callback function when creating the timer. When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER. <br><br>The wParam parameter of the WM_TIMER message contains the value of the nIDEvent parameter. <br><br>
 
没有窗体,上面的不好用。<br>用线程模拟:sleep
 
用SetTimer;去 回调timerproc 事件 在其中 处理代码。<br>killtimer &nbsp;结束。
 
能否贴代码
 
用函数啊。<br>比如<br>var te:integer;<br><br>begin<br>for te=8 do<br>begin<br>{执行代码}<br>sleep(1000);<br>end;<br>end;<br><br>程序过程中不需要对te进行赋值。所以te永远也不可能=8 所以就一直会执行这个for循环。然后一句sleep(1000)就是一个延时一秒的函数。即可达到timer的功能。
 
打开ExtCtrls.pas,照着TTimer的源代码自己写一个就行了。<br>不用窗体,也不用TApplication
 
可以用定时器内核对象
 
啊。没有例子吗?
 
还不如开个线程用<br>while(true) do<br>begin<br>........<br>end;<br><br>今天看到一java例子的服务器的监听就是用的这种方式<br>
 
后退
顶部