各位前辈,我平常很少用VC,最近由于要做一个小项目,需要用VC,就临时学习了一下。
现在要让程序每过1分钟就将某段代码执行一次,不知在VC中如何实现,请指教!

解决方案 »

  1.   

    SetTimer
    The SetTimer function creates a timer with the specified time-out value. UINT_PTR SetTimer(
      HWND hWnd,              // handle to window
      UINT_PTR nIDEvent,      // timer identifier
      UINT uElapse,           // time-out value
      TIMERPROC lpTimerFunc   // timer procedure
    );
    Parameters
    hWnd 
    [in] 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. 
    nIDEvent 
    [in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. 
    If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored. uElapse 
    [in] Specifies the time-out value, in milliseconds. 
    lpTimerFunc 
    [in] Pointer to the function to be notified when the time-out value elapses. For more information about the function, see TimerProc. 
    If lpTimerFunc is NULL, the system posts a WM_TIMER message to the application queue. The hwnd member of the message's MSG structure contains the value of the hWnd parameter. Return Values
    If the function succeeds and the hWnd parameter is NULL, the return value is an integer identifying the new timer. An application can pass this value to the KillTimer function to destroy the timer. If the function succeeds and the hWnd parameter is not NULL, then the return value is a nonzero integer. An application can pass the value of the nIDTimer parameter to the KillTimer function to destroy the timer.If the function fails to create a timer, the return value is zero. To get extended error information, call GetLastError.
      

  2.   

    SetTimer(),打开定时器
    KillTimer,关闭定时器
    OnTimer,响应定时器,这个在类向导里添加,消息名称好像是WM_TIMER具体用法非常简单,自己看msdn