SetTimer函数第3个参数怎么使用???(TimerProc),自己写了一个方法,但不知将其作为一个参数放进这个SetTimer中,有没有一个简单例子???

解决方案 »

  1.   

    SDK中,第三个参数为时间
    The SetTimer function creates a timer with the specified time-out value. 
    Syntax
    UINT_PTR SetTimer(          HWND hWnd,
        UINT_PTR nIDEvent,
        UINT uElapse,
        TIMERPROC lpTimerFunc
    );
    ParametershWnd
    [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. 
    Windows NT/2000/XP: If uElapse is greater than 0x7fffffff, the timeout is set to 1.Windows 2000/XP: If uElapse is less than 10, the timeout is set to 10.Windows Server 2003: If uElapse is greater than 0x7fffffff, the timeout is set to 0x7fffffff. 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 ValueIf 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 nIDEvent 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(1,2000,(TIMERPROC)OnTimerProc); VOID CALLBACK OnTimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
    {
    //your code
    }
      

  3.   


    我是用对话框上一个Static控件的SetTimer刚才试了一下 alon21 的方法,可以运行,但我在OnTimerProc这个方法里怎么控制这个Static的显示呢????
      

  4.   

    GetDlgItem(ID_STATIC)->SetWindowText('aaaa');
      

  5.   


    OnTimerProc 并不属于对话框这个类中的一个方法,怎么可以用GetDlgItem(ID_STATIC)呢?????
      

  6.   

    UINT_PTR SetTimer(          HWND hWnd,
        UINT_PTR nIDEvent,
        UINT uElapse,
        TIMERPROC lpTimerFunc
    );
    Parameters第一個是,窗口句柄hWnd,不用說了;
    第二個是,Timer的ID,你在設置多個Timer的時候,就可以在TimerProc中加以區別了,是哪個Timer引發的.
    第三個是,執行周期,以微秒為單位,如果是1秒就設置為1000.
    第三個是,TimerPorc函數指針.
      

  7.   

    To ShiGang:这个说明看过了,但看过也不会用啊!!!!===========================================OnTimerProc 并不属于对话框这个类中的一个方法,怎么可以用GetDlgItem(ID_STATIC)呢?????
      

  8.   


    有什么办法操作 所说的 ID_STATIC 啊?????
      

  9.   

    把窗口指针传进来不就可以了,在把这个ID_STATIC定义一个变量
      

  10.   

    如果对类成员进行处理的话,不如用OnTimer,不要写回调函数
      

  11.   


    to suisuibianbian:窗口的指针怎么传进来这个回调方法里呢,第1个参数是HWND怎么转换?????
      

  12.   

    从句柄得到指针用CWnd::FromHandle
      

  13.   

    比如,你的窗口是个对话框:
    CMyDlg * pDlg = (CMyDlg *)CWnd::FromHandle(hWnd);
      

  14.   

    又忘了说了,其实在你的回调函数中不用窗口指针也能做的:
    GetDlgItem(hWnd,ID_STATIC)->SetWindowText('aaaa');
      

  15.   

    to pomelowu :我在程序中只做了以下这些:
    SetTimer(1,2000,(TIMERPROC)OnTimerProc); VOID CALLBACK OnTimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
    {
    //your code
    }在 (TIMERPROC)OnTimerProc 中,怎么传????在调用之前,怎么声明?????
      

  16.   

    把OnTimerProc函数定义放到cpp文件的尽可能前面(制定好保证在调用SetTimer的函数前面)
    另外,这样设置Timer:
    ::SetTimer(GetSafeHwnd(),1,2000,(TIMERPROC)OnTimerProc);
      

  17.   

    OnTimerProc 不要做為類成員函數,(因為類成員函數,尾部都隱藏了一個this指針),如果非要讓它成為類成員函數的話,就設置為Static型的去掉this指針..如果是靜態類成員函數,就可以直接調用.
    如果是外部調用.就可::SetTimer(AfxGetApp()->m_pMainWnd->m_hWnd,ID_TIMER1,nSecond *1000 ,(TIMERPROC)OnTimerProc);