想在一个非窗口类中实现一个定时程序,但MFC定时器只支持窗口类中使用,请问怎么在一个非窗口类中实现定时器的功能呢,在网上搜到一篇文章,但那都是通过窗口类去掉用的,相当于只是把MFC的定时器重新封装了一下。所以大家可以把我这里说的窗口类理角为控制台程序吧!先谢了!

解决方案 »

  1.   

    用一个独立线程封装Sleep函数就可以了
      

  2.   

    不好意思,我这是WinCE系统,再添加新的线程对系统资源来说已经不允许了,大家再帮看看还有没有什么方法呢!
      

  3.   

    用sleep(int x)可实现,
    不过我这里是用_sleep(int x)不知道是不是版本的原因
      

  4.   

    sleep(int x)得像一楼说的一样,得是个独立的线程啊。
      

  5.   

    给楼主贴段MSDN上关于SetTimer的说明:SetTimer
        This function creates a timer with the specified time-out value.     UINT SetTimer(
            HWND hWnd, 
            UINT nIDEvent, 
            UINT uElapse, 
            TIMERPROC lpTimerFunc ); 
    Parameters
        hWnd 
        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 
        Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. 
        uElapse 
        Specifies the time-out value, in milliseconds. 
        lpTimerFunc 
        Long 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. 
      

  6.   

    非窗口类也可以调用SetTimer啊SetTimer是从user32.dll导出的WINAPI,只不过大多数人用的SetTimer是CWnd::SetTimer。除了SetTimer,你还可以Sleep、COleDateTime+COleDateTimeSpan、GetTickCount、timeGetTime、timeSetEvent、QueryPerformanceFrequency+QueryPerformanceCounter,方法很多