我在创建的窗口程序中填写如下代码:
UINT  timerid = SetTimer(hWnd,0,2000,NULL);
KillTimer(hWnd,0);
消息循环中的代码是:
case WM_TIMER:
   switch(wParam)
   {
     case 0:
MessageBox(NULL,"you lose!","you lose!",MB_OK);

break;
}
这时候killTimer成功了
但是,当我把代码改成这样的时候:
UINT  timerid = SetTimer(hWnd,0,2000,NULL);
case WM_TIMER:
       switch(wParam)
{
case 0:
KillTimer(hWnd,0);
MessageBox(NULL,"you lose!","you lose!",MB_OK);

break;
}
KillTimer就失败了。大家帮帮忙啊。

解决方案 »

  1.   

    MSN上说nIDEvent
    [in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, and the nIDEvent does not match an existing timer then it is ignored and a new timer ID is generated. 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. If the call is not intended to replace an existing timer, nIDEvent should be 0 if the hWnd is NULL. nIDEvent最好不要设置为0
      

  2.   

    UINT timerid = SetTimer(hWnd,0,2000,NULL);
    KillTimer(hWnd,0);
    =============
    改成:
    KillTimer(timerid ,0);试试
      

  3.   

    还是不行诶。。
    错误:error C2065: 'timerid' : undeclared identifier
    Error executing cl.exe.
      

  4.   

    timerid把这个变量声明为全局或是成员变量!