Timer Functions

Started by Rolf Brandt, May 29, 2014, 01:32:32 PM

Previous topic - Next topic

Rolf Brandt

I just needed to update an older program with some functionality to change timer intervals during runtime. Since PowerBasic does not have any special functions for it I wrote one.

Maybe it is helpful for someone else. There is also a little demo project attached to demonstrate the use of it.

[Edit: 2014-05-29 18:14]
I added also Timerfunctions.zip. It contains a folder which you can place in FF3's codestore so that you have the functions on hand with F8.

Rolf


'timerfunctions.inc

'--------------------------------------------------------------------------------
' CreateOrChangeTimer
' Create a timer or change it's interval
'--------------------------------------------------------------------------------
Function CreateOrChangeTimer(ParentForm  As Dword, _
                            TimerHwnd    As Dword, _
                            TimerIdc     As Dword, _
                            NewInterval  As Long   _
                            ) As Long
                             
   KillTimer ParentForm, TimerIdc
   TimerHwnd = SetTimer(ParentForm, TimerIdc, NewInterval, ByVal %Null)
End Function


'--------------------------------------------------------------------------------
' DisableTimer
' Disable (kill) a timer
'--------------------------------------------------------------------------------
Function DisableTimer(ParentForm  As Dword, _
                      TimerIdc    As Dword  _
                      ) As Long
                             
   KillTimer ParentForm, TimerIdc
End Function



'Usage

'Change interval of an existing timer or recreate the timeer
CreateOrChangeTimer(HWND_FORM1,HWND_FORM1_TIMER1,IDC_FORM1_TIMER1,500)

'Disable the timer (in reality kill it)
DisableTimer(HWND_FORM1, IDC_FORM1_TIMER1)

'...and enable it again (recreate it)
CreateOrChangeTimer(HWND_FORM1,HWND_FORM1_TIMER1,IDC_FORM1_TIMER1,2000)


Rolf Brandt
http://www.rbsoft.eu
http://www.taxifreeware.com
I cook with wine, sometimes I even add it to the food.
(W. C. Fields)

Jim Dunn

Rolf, once again, you're such a generous person, we appreciate it!!!
3.14159265358979323846264338327950
"Ok, yes... I like pie... um, I meant, pi."

Pedro Marquez

It is appreciated, thanks.

Petrus Vorster

Thanks Rolf

Very kind to share!
-Regards
Peter

John Montenigro