Qt實現MFC的WM_IDLE機制.doc

   win32 有一個消息是 WM_IDLE,而在MFC裏面的也有一個virtualBOOLOnIdle(LONGlCount)的函數與之相對應,而在MSDN中對該函數的解釋是:

  Override this member function to perform idle-time processing. OnIdle is called in the default message loop when the application’s message queue is empty. Use your override to call your own background idle-handler tasks.


   大概意思是重寫這個成員方法去執行空閒處理。OnIdle函數將在應用程序的消息隊列爲空時在默認的消息循環隊列中被調用。你可以用你的重載函數去調用你自已的後臺空閒處理任務。


   用Qt做開發時,我需要在空閒時在後臺調用的我空閒處理地,那麼Qt裏面有這個東西嗎?

   經過查閱QT的幫助文檔,發現startTime除了能夠開起一個定時執行的定時器外還能實現這一功能。看看QT中該函數的解說。

int QObject::startTimer ( intinterval)

Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.

A timer event will occur everyintervalmilliseconds untilkillTimer() is called. Ifintervalis 0, then the timer event occurs once every time there are no more window system events to process.


    如果將傳入參數設置爲0,這個時鐘在每一次窗口系統事件爲空時就會發生。也就是說我們就可以將傳入參數設置爲0,然後在重寫的函數中實現我們自已的空閒處理。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章