我要做一个小程序,即有一个命令按钮,在消息处理函数中执行命令,我如何使其隔一秒钟执行一次?

解决方案 »

  1.   

    用SetTimer函数起用一个时间,KillTiemr函数终止一个时间
    在OnTimer事件中写处理程序
      

  2.   

    比如说,我可以在一个按钮的ONOK()中调用Settimer函数,时间到了以后就进入OnTimer()中写处理程序,那何时调用KillTimer()函数?
      

  3.   

    CWnd::SetTimer
    UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );
    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.
      

  4.   

    BOOL KillTimer( int nIDEvent );
    Specifies the outcome of the function. The value is nonzero if the event was killed. It is 0 if the KillTimer member function could not find the specified timer event.ParametersnIDEventThe value of the timer event passed to SetTimer.
      

  5.   

    看一下这段很简单的程序:
    为什么void CMy3Dlg::OnTimer(UINT nIDEvent)一点用都没有?单步执行时根本没进入函数体。void CMy3Dlg::OnRolchange() //命令按钮的处理函数,调用SetTimer
    {
    // TODO: Add your control notification handler code here
    CWnd::SetTimer(1, 1000, NULL); 
    }void CMy3Dlg::OnTimer(UINT nIDEvent)
    {
        CMy3Dlg dlg;

    if(nIDEvent == 1)
    {
                dlg.m_strDisplay="I am succes!";
                dlg.DoModal();     
    }
    CDialog::OnTimer(nIDEvent);}
      

  6.   

    是不是OnTimer函数我加得不对,我是CMy3Dlg类添加的成员函数,函数内容自己写。