DWORD time1 = GetTickCount();
DWORD time2 = 0;
while(1)
{
time2 = GetTickCount();
if( time2-time1 >=20000 )
{
time1=GetTickCount();
...
}
}不知行不行

解决方案 »

  1.   

    如果是在windows下,可以利用ON_TIMER事件
      

  2.   

    to wabc:
    能否说具体一点,给一个例子好吗?
      

  3.   

    设定一个定时器,定时20秒:UINT_PTR SetTimer(
      HWND hWnd,              // handle to window
      UINT_PTR nIDEvent,      // timer identifier
      UINT uElapse,           // time-out value    =>   设为20000毫秒
      TIMERPROC lpTimerFunc   // timer procedure
    );
      

  4.   

    调用事件ONTIME()在msdn中查询相关信息就行了
      

  5.   


    这是一个SDK编程中用TIMER的例子switch (Message)
        {
            case WM_INITDIALOG:
             
    SetTimer(hDlg,       // handle of window for timer messages
    103,           // timer identifier
    500,           // time-out value
    (TIMERPROC)DlgProc  // address of timer procedure
    );
    return(TRUE); case WM_TIMER:
       KillTimer(hDlg,103);
       EndDialog (hDlg, TRUE);
       return (TRUE);
             default:
                return(FALSE);
    }
      

  6.   

    还是写完整点吧,用这个窗口函数的对话框将在建立后的500ms后关闭int
    CALLBACK
    NoticeDlgProc(
        HWND        hDlg,
        UINT        Message,
        WPARAM      wParam,
        LPARAM      lParam)
    {
    switch (Message)
        {
            case WM_INITDIALOG:
             
        SetTimer(hDlg,       // handle of window for timer messages
        103,           // timer identifier
        500,           // time-out value
        (TIMERPROC)DlgProc  // address of timer procedure
        );
        return(TRUE);    case WM_TIMER:
           KillTimer(hDlg,103);
           EndDialog (hDlg, TRUE);
           return (TRUE);
             default:
                return(FALSE);
       }
    }
      

  7.   

    还嫌不好?WINDOWS就这么做的 :)