控制台支持MFC,要使用定时器
void CALLBACK TimerCallProc(...)
main()
{
  ::SetTimer( NULL, 1, 100, TimerCallProc );
  sleep(10000);
}
这样好像使用不了定时器,怎样解决才能实现控制台下使用定时器???

解决方案 »

  1.   

    到msdn中找找吧,我想这样的问题应该不是问题
    当窗口为空的时候,第二个参数也是无效的
      

  2.   

    晕,你写的哪门子的定时器????
    1 下面是MFC中定时器的用法,分别用两个按钮OnStartTimer,OnStopTimer
    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);
    }2 下面是SDK消息方式的定时器
    SetTimer(hwnd,             // handle to main window 
        IDT_TIMER1,            // timer identifier 
        10000,                 // 10-second interval 
        (TIMERPROC) NULL);     // no timer callback 
     
    SetTimer(hwnd,             // handle to main window 
        IDT_TIMER2,            // timer identifier 
        300000,                // 5-minute interval 
        (TIMERPROC) NULL);     // no timer callback 
    .....
    case WM_TIMER: 
     
        switch (wParam) 
        { 
            case IDT_TIMER1: 
                // Process the 10-second timer. 
     
                 return 0; 
     
            case IDT_TIMER2: 
                // Process the 5-minute timer.             return 0; 
        } 3 SDK方式指定回调函数来处理定时消息SetTimer(hwnd,                // handle to main window 
        IDT_TIMER3,               // timer identifier 
        5000,                     // 5-second interval 
        (TIMERPROC) MyTimerProc); // timer callback ........
    VOID CALLBACK TimerProc(
      HWND hwnd,         // handle to window
      UINT uMsg,         // WM_TIMER message
      UINT_PTR idEvent,  // timer identifier
      DWORD dwTime       // current system time
    )//定时溢出就会调用这个回调函数
    {
    ............
    }
      

  3.   

    #include <windows.h>
    #include <stdio.h>int main()
    {
        HANDLE hTimer = NULL;
        LARGE_INTEGER liDueTime;    liDueTime.QuadPart=-100000000;    // Create a waitable timer.
        hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
        if (!hTimer)
        {
            printf("CreateWaitableTimer failed (%d)\n", GetLastError());
            return 1;
        }    printf("Waiting for 10 seconds...\n");    // Set a timer to wait for 10 seconds.
        if (!SetWaitableTimer(
            hTimer, &liDueTime, 0, NULL, NULL, 0))
        {
            printf("SetWaitableTimer failed (%d)\n", GetLastError());
            return 2;
        }    // Wait for the timer.    if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
            printf("WaitForSingleObject failed (%d)\n", GetLastError());
        else printf("Timer was signaled.\n");    return 0;
    }