Does window timer still exist?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Does window timer still exist?

Post by Korolev Michael »

I suppose, we need a function kinda "IsWindowTimer", that checks whether timer still alive.
Just like "IsThread"

Oh my god, I found duplicate 2010-year thread.
Former user of pirated PB.
Now registered user :].
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Does window timer still exist?

Post by Julian »

Threads can be stopped many many ways so IsThread is useful. However a window timer created with AddWindowTimer will run until you cancel it with RemoveWindowTimer (or I assume CloseWindow) so you should be able to track it quite easily?
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: Does window timer still exist?

Post by Korolev Michael »

track it quite easily
HOW?

When I cancelled timer, how then I can check, is it running or not?
Former user of pirated PB.
Now registered user :].
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Does window timer still exist?

Post by Demivec »

Korolev Michael wrote:
track it quite easily
HOW?

When I cancelled timer, how then I can check, is it running or not?
Maybe:

Code: Select all

Global NewMap timers()

Procedure _AddWindowTimer(window, timer, timeout)
  timers(Str(window) + "_" + Str(timer)) = timeout ;signal timer present
  AddWindowTimer(window, timer, timeout)
EndProcedure

Procedure _RemoveWindowTimer(window, timer)
  If FindMapElement(timers(), Str(window) + "_" + Str(timer))
    RemoveWindowTimer(window, timer)
    DeleteMapElement(timers())
  EndIf
EndProcedure

Procedure IsWindowTimer(window, timer)
  ProcedureReturn Bool(FindMapElement(timers(), Str(window) + "_" + Str(timer)) <> 0)
EndProcedure

Procedure GetWindowTimerTimeout(window, timer)
  If FindMapElement(timers(), Str(window) + "_" + Str(timer))
    ProcedureReturn timers()  
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

Macro AddWindowTimer(window, timer, timeout)
 _AddWindowTimer(window, timer, timeout)
EndMacro

Macro RemoveWindowTimer(window, timer)
  _RemoveWindowTimer(window, timer)
EndMacro

Macro ChangeWindowTimerTimeout(window, timer, newTimeout)
  _RemoveWindowTimer(window, timer)
  _AddWindowTimer(window, timer, newTimeout)
EndMacro
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: Does window timer still exist?

Post by Korolev Michael »

Thanks, that's good solution.
Didn't think about overloading.
Former user of pirated PB.
Now registered user :].
Post Reply