????3??????????

???????????????????????????KillTimer??????????KillTimer?????????
BOOL   KillTimer(
HWND   hWnd??   //   ??????
UINT_PTR   uIDEvent   //   ID
);

??????MFC???????????????????KillTimer(int   nIDEvent)????????????

????????

#include  
#include  
VOID   CALLBACK   TimerProc(HWND   hwnd??UINT   uMsg??UINT   idEvent??DWORD   dwTime);
VOID   CALLBACK   TimerProc(HWND   hwnd??UINT   uMsg??UINT   idEvent??DWORD   dwTime)
{
std::cout   < <   "hello "   < <   std::endl;
}

void   main()
{
int   timer1   =   1;
HWND   hwndTimer;      
MSG   msg;                   

SetTimer(NULL??timer1??5000??TimerProc);
int   itemp;
while ( (itemp = GetMessage(&msg?? NULL??NULL??NULL))&& (itemp!=0) &&  (-1 !=  itemp))
{  
   if   (msg.message   ==   WM_TIMER)  
   {  
    std::cout   < <   "i   got   the   message "   < <   std::endl;
    TranslateMessage(&msg);  
    DispatchMessage(&msg);    
    }  
}  
}

??????????£?

????i   got   the   message
????hello
????i   got   the   message
????hello
????i   got   the   message
????hello


---------------------------------------------------------------------------------------------------------------------------

// timer.cpp : ??????????ó????????
//

#include "stdafx.h"
#include    
#include    
#include  

unsigned   long   WINAPI   Thread(PVOID   pvoid); 
void   main() 

    DWORD   dwThreadId; 
    printf("use   timer   in   workthread   of   console   application "); 
    HANDLE   hThread   =   CreateThread(   
        NULL??                                                 //   no   security   attributes   
        0??                                                       //   use   default   stack   size     
        Thread??                                     //   thread   function   
        0??                                 //   argument   to   thread   function   
        0??                                                       //   use   default   creation   flags   
        &dwThreadId);   
    DWORD   dwwait=WaitForSingleObject(hThread??1000*30); 
    switch(dwwait) 
    { 
    case   WAIT_ABANDONED: 
        printf("main   thread   WaitForSingleObject   return   WAIT_ABANDONED "); 
        break; 
    case   WAIT_OBJECT_0: 
        printf("main   thread   WaitForSingleObject   return   WAIT_OBJECT_0 "); 
        break; 
    case   WAIT_TIMEOUT: 
        printf("main   thread   WaitForSingleObject   return   WAIT_TIMEOUT "); 
        break; 
    } 
    CloseHandle(hThread); 
    _getch(); 
}

unsigned   long   WINAPI   Thread(PVOID   pvoid) 

    MSG   msg; 
    PeekMessage(&msg??   NULL??   WM_USER??   WM_USER??   PM_NOREMOVE); 
    UINT   timerid=SetTimer(NULL??111??3000??NULL); 
    BOOL   bRet; 
    int   count   =0; 
    while(   (bRet   =   GetMessage(   &msg??   NULL??   0??   0   ))   !=   0) 
    {   
        if   (bRet   ==   -1) 
        { 
            //   handle   the   error   and   possibly   exit 
        } 
        else 
            if(msg.message==WM_TIMER) 
            { 
                count++; 
                printf("WM_TIMER   in   work   thread   count=%d "??count); 
                if(count>4) 
                    break; 
            } 
            else 
            { 
                TranslateMessage(&msg);   
                DispatchMessage(&msg);   
            } 
    } 
    KillTimer(NULL??timerid); 
    printf("thread   end   here "); 
    return   0;