如题。关键是想确保已经SetTimer!

解决方案 »

  1.   

    自己建立逻辑变量,settime是置位,killtimer前查询
      

  2.   

    SetTimer会返回一个id。
    你kill的时候就使用这个id。 不会kill出问题的。
      

  3.   

    即便是你没有settimer
    killtimer也没事的不过你的逻辑是很值得赞同的
      

  4.   

    用UINT_PTR变量保存settimer的返回值,初始值为0,表示没有TIMER,settimer的返回值不会是零,所以当UINT_PTR值为非零时,表示有TIMER。
      

  5.   

    killtimer的时候,把UINT_PTR的值传入即可,killtimer完后,再将UINT_PTR的值设为初始值0
      

  6.   

    SetTimer Function
    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.
      

  7.   

    killtimer  自己会做判断吧。。
      

  8.   

    没必要判断,放心KillTimer,难道你还有别的目的?
      

  9.   


    直接 KillTimer 就行,不存在它就直接返回一个错误!
      

  10.   

    LONG volatile IsTimerSet = 0;if (SetTimer(.........))
    {
      InterlockedExchange(&IsTimerSet,1); // IsTimerSet为1时,就是SetTimer成功了
    }// KillTimer前
    LONG volatile CurrentValue = 0;
    InterlockedExchange(&CurrentValue,IsTimerSet);
    if (CurrentValue)
     {
        KillTimer()
     }这只是一种好的编程习惯,KillTimer()就算删除不存在的Timer,也不会返回任何错误,因为KillTimer()会先查看是否有这个Timer,然后再Kill掉,如果没查到有这个Timer,自然不会删除了.