有个问题请教网上高手:
我在CView类中写了一个设置时钟函数如下:
if(SetTimer(ABC, 30, NULL))
{
  int e = GetLastError();
}在函数运行过程中 e 的值为 0 ,但仍能响应OnTimer,不知为何。

解决方案 »

  1.   

    if(SetTimer(ABC, 30, NULL)) 已经启动定时器了,当然ontimer会响应
      

  2.   

    SetTimer()函数创建新的定时器成功后返回非0值,这个值确定新的定时器
    既然能看到e的值,自然是定时器创建成功,
    必定要出发OnTimer()函数,只有不成功时才使用GetLastError()函数
    获取错误信息
      

  3.   

    如果设置成功,就去取的错误代码.GetLastError()当然返回空了,因为你的程序没错啊.
      

  4.   

    MSDN上的原话:
    Return Values
    If the function succeeds, the return value is an integer identifying the new timer. An application can pass this value, or the string identifier, if it exists, 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.它告诉你函数执行失败的时候返回值为0,此时可以调用GetLastError获取错误信息。
      

  5.   

    应该这样才会对
    if(!SetTimer(ABC, 30, NULL)) 

      int e = GetLastError(); 
    }
    给分吧