我有一段循环代码,需要每隔2s循环一次,这2s的间隙之间需要响应其他消息。请问怎么做?

解决方案 »

  1.   

    把需要循环的内容放到OnTimer中,或者,放到辅助线程中循环
      

  2.   

    设定定时器为两秒,OnTimer中处理,只要函数不长就该可以,要是函数耗时,则应该另外启动线程
      

  3.   

    设定定时器为两秒,OnTimer中处理,只要函数不长就该可以,要是函数耗时,则应该另外启动线程
      

  4.   

    在OnTimer函数中具体是怎么做的呢?
      

  5.   

    SetTimer()这个函数中的参数的意思是什么?
      

  6.   

    CWnd::SetTimer
    UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );Return ValueThe timer identifier of the new timer if the function is successful. An application passes this value to the KillTimer member function to kill the timer. Nonzero if successful; otherwise 0.ParametersnIDEventSpecifies a nonzero timer identifier.nElapseSpecifies the time-out value, in milliseconds.lpfnTimerSpecifies the address of the application-supplied TimerProc callback function that processes the WM_TIMER messages. If this parameter is NULL, the WM_TIMER messages are placed in the application’s message queue and handled by the CWnd object.ResInstalls a system timer. A time-out value is specified, and every time a time-out occurs, the system posts aWM_TIMER message to the installing application’s message queue or passes the message to an application-defined TimerProc callback function. The lpfnTimer callback function need not be named TimerProc, but it must be defined as follows:void CALLBACK EXPORT TimerProc(
       HWND hWnd,      // handle of CWnd that called SetTimer
       UINT nMsg,      // WM_TIMER
       UINT nIDEvent   // timer identification
       DWORD dwTime    // system time
    );Timers are a limited global resource; therefore it is important that an application check the value returned by the SetTimer member function to verify that a timer is actually available.Example// This example shows how to use CWnd::SetTimer, CWnd::KillTimer, and how to handle WM_TIMER messages. A timer is set up to send a WM_TIMER message to the main frame window every 2 seconds in OnStartTimer(). OnStopTimer will stop the timer by calling CWnd::KillTimer. OnTimer was set up through class wizard to handle WM_TIMER messages for the main frame window.  In this example the PC speaker will beep every 2 seconds.void CMainFrame::OnStartTimer() 
    {
       m_nTimer = SetTimer(1, 2000, 0);
    }void CMainFrame::OnStopTimer() 
    {
       KillTimer(m_nTimer);   
    }void CMainFrame::OnTimer(UINT nIDEvent) 
    {
       MessageBeep(0xFFFFFFFF);   // Beep   // Call base class handler.
       CMDIFrameWnd::OnTimer(nIDEvent);
    }
      

  7.   

    m_timer=SetTimer(1(标识),2000,NULL);
    最后一个参数为NULL表示在OnTimer中处理
    killTimer(m_timer);
      

  8.   

    要用一个按钮响应OnTimer中的函数,怎么做啊?