Interrupt Timer - by Code Maker 2017
This program can periodic execute code without any calls from the
main loop
I am sure there is many applications opportunities for an interrupt
timer like this.
Notes.
1.
You sould try to keep the timer delay above 10 milliseconds or
else it will overload your system, to quote MS API SDK help files
"Periodic timer events with an event delay of 10 milliseconds or less
consume a significant portion of CPU resources."
2.
The interrupt timer will bee killed if the window to which it has been
associated is closed.
`Interrupt Timer - by Code Maker 2017
`this code needs the Matrix1 plugin to compile
`Note 1.
`You sould try to keep the timer delay above 10 milliseconds or
`else it will overload your system, to quote MS API SDK help files
`"Periodic timer events with an event delay of 10 milliseconds or less
`consume a significant portion of CPU resources."
`Note 2.
`The interrupt timer will bee killed if the window to which it has been
`associated is closed.
init:
global counter
global ittext$
sync on
sync rate 60
backdrop on
user32DLL = 1
timerdelay = 1000 `timer delay in milliseconds
x = screen width()
y = screen height()+50
text$ = "mainloop is dooing this..."
set window title "Interrupt Timer by Code Maker 2017"
`load user 32 bit dll
load dll "user32.dll", user32DLL
`get window handle, identifies the window to be associated with the timer
WindowHWND = call dll(user32DLL, "GetActiveWindow")
`get pointer to function
InterruptTimerPTR = get ptr to function("InterruptTimer")
`make timer, it starts immediately
TimerID = call dll(user32DLL, "SetTimer", WindowHWND, 1, timerdelay, InterruptTimerPTR)
`main loop
do
dec x
dec y
if x<-text width(text$) then x=screen width()
if y<-text height(text$) then y=screen height()+15
if inkey$()<>"" then exit
sync
text x, 200, text$
text screen width()/2-text width(ittext$)/2, y, ittext$
loop
`clean up before exit
s = call dll(user32DLL, "KillTimer", WindowHWND, TimerID)
delete dll user32DLL
`exit program
end
`function, this is what the interrupt timer will do
function InterruptTimer()
inc counter
ittext$ = "interrupt timer is doing this, without any calls from the mainloop " + str$(counter)
endfunction