EventSourceHandle changed by timer?!

BlitzMax Forums/BlitzMax GUI Programming/EventSourceHandle changed by timer?!

It depends upon the structure of your code. If most of your code handling is through event queues, then you might want to try processing the timer events through a hook that returns Null. This will mean that the event queue will never see any of time timer events and so will not get clogged up by them.

Import MaxGUI.Drivers

SuperStrict

Global window:TGadget = CreateWindow:TGadget("EventSource Test", Desktop().width*0.35, Desktop().height*0.35, 320, 240)', Null, WINDOW_CENTER | WINDOW_CLIENTCOORDS)
Global panel:TGadget = CreatePanel(0,0,ClientWidth(window),ClientHeight(window),window,PANEL_ACTIVE|PANEL_GROUP,"click repeatedly here to see EventSourceHandle change!")
Global label:TGadget = CreateLabel("Event Source Address = $",60,60,150,20,panel)
Global timer:TTimer = CreateTimer(10)

Function MyHook:Object(iId:Int,tData:Object,tContext:Object)
	
	Local event:TEvent = TEvent(tData)
	If Not event Then Return Null
	
	Select event.id
		Case EVENT_TIMERTICK
			If TimerTicks(timer)>10
				StopTimer(timer)
				timer = CreateTimer(10)
				Return Null 	'Don't return the timer event to add to the event queue.
			EndIf
		Case EVENT_MOUSEDOWN
			SetGadgetText(label, "Address() = "+Int( Byte Ptr event.source ))
	EndSelect
	
	Return tData
	
End Function

AddHook EmitEventHook, MyHook

Repeat
	Select WaitEvent()
		Case EVENT_WINDOWCLOSE
			End
	EndSelect
Forever
Does this work any better?