SetTtimer的第一个参数要怎么获得?可以自己随意指定吗?
例如:SetTimer(79,2000,NULL);
我像下面这样建立一个时间循环可以吗?
void CAPPDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
SetTimer(79,2000,NULL);
}
void CMenViewerDlg::OnTimer(UINT nIDEvent) 
{
// TODO: Add your message handler code here and/or call default
         if(Myfunction())
                   KillTimer(nIDEvent);
CDialog::OnTimer(nIDEvent);
}

解决方案 »

  1.   

    可以自己指定
    void CAPPDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    SetTimer(79,2000,NULL);
    }
    void CMenViewerDlg::OnTimer(UINT nIDEvent) 
    {
            switch(nIDEvent)
            {
            case 79:
                KillTimer(79);
                break;
            default:
                //
            }
            CDialog::OnTimer(nIDEvent);
    }
      

  2.   

    SetTtimer的第一个参数要怎么获得?可以自己随意指定吗?
    79为Timer的ID号;可以自己指定,但不能随意。
    nIDEvent为传入的Timer的ID号
      

  3.   

    SetTimer Function--------------------------------------------------------------------------------The SetTimer function creates a timer with the specified time-out value. SyntaxUINT_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.
    ResAn application can process WM_TIMER messages by including a WM_TIMER case statement in the window procedure or by specifying a TimerProc callback function when creating the timer. When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER. The wParam parameter of the WM_TIMER message contains the value of the nIDEvent parameter. The timer identifier, nIDEvent, is specific to the associated window. Another window can have its own timer which has the same identifier as a timer owned by another window. The timers are distinct. SetTimer can reuse timer IDs in the case where hWnd is NULL. ExampleFor an example, see Creating a Timer.Function InformationHeader Declared in Winuser.h, include Windows.h 
    Import library User32.lib 
    Minimum operating systems Windows 95, Windows NT 3.1 See AlsoTimers Overview, KillTimer, MSG, TimerProc, WM_TIMER
      

  4.   

    在CWnd中的SetTimer第一个参数是事件ID,可以随便设置,至于你说的时间循环我不是很明白,如果你的意思是每隔一定时间长度要执行一个操作的话,就不用KillTimer
    SetTimer就是一个时间循环,每隔第二个参数规定的时间间隔就会触发WM_TIMER事件,这样就是一个时间循环,而KillTimer是用来终止CWnd去获取与nIDEvent事件相关的WM_TIMER事件的。
      

  5.   

    robinzo(兔子) ( ):      谢谢你,我说的时间循环就是每隔一定时间长度要执行一个操作,我不知道标准术语是什么,就只好这样叫了.我说用KillTimer的意思是循环总要有个终止的时候吧?不然好象和死循环一样.