Refresh problem

BlitzPlus Forums/BlitzPlus Programming/Refresh problem

hub(Posted 2003) [#1]
Hi !
I've a status bar into my window. I want display millisecs()... but b+ don't refresh the window...How to force b+ to refresh the display ?
Thanks !

Global Win1

Function CreateWin1()

	; %10010 Or %00001
	Win1 = CreateWindow("bayre.com",73,149,200,220,Desktop(),1+8+16)
	
	SetStatusText Win1, "Bienvenue."

End Function


CreateWin1()

Repeat
	
	
	SetStatusText Win1, MilliSecs()
	
	
	Select WaitEvent()
	
	Case $803 : End

	End Select
			
Forever



marksibly(Posted 2003) [#2]
Hi,

WaitEvent waits 'forever', or until an event occurs so your program is getting 'stuck' inside the waitevent command.

Changing WaitEvent() to WaitEvent(0) will fix it. 0 means 'wait for an event, or until 0 millisecs have elapsed'.

However, this will chew up all the CPU time, which will cause other programs to run slower.


Hotcakes(Posted 2003) [#3]
Additionally, WaitEvent(1) will time out after 1 millisecond, which will be slightly (not much) of a less of a hog of the CPU...

A better way would be to Create a Timer and then check inside your loop (inside the Select part) for the Timer Event... that way your status bar can be updated as often as you want and everything else can wait it's turn.


hub(Posted 2003) [#4]
Many thanks Mark and Toby !
Try the following code, when you move the mouse into the canvas waitevent(1000) seems to be ignored ???

When you specify waitevent(1000) and when others programs works into my machine, each 1000 ms, windows try to 'update/execute' the commands into the b+ program ? Is it true ?

Global Win1
Global Canvas1
Global Seconds

Function CreateWin1()

	Win1 = CreateWindow("bayre.com",73,149,200,220,Desktop(),1+8+16)
	
	Canvas1 = CreateCanvas(5,5,185,120,Win1,0)
	SetGadgetLayout Canvas1,1,0,1,0
	SetBuffer CanvasBuffer(Canvas1)
	ClsColor 34,85,136
	Cls
	
End Function


CreateWin1()

Repeat
	
	Select WaitEvent(1000)
	
	Case $803 : End

	End Select

	Seconds = Seconds + 1	
	SetStatusText Win1, "Seconds=" + seconds
			
Forever



Hotcakes(Posted 2003) [#5]
OK HERE your problem is that if an Event is generated, WaitEvent will stop waiting straight away, which means whenever a mouse move event happens inside your canvas, your Seconds counter gets updated ahead of schedule. Solution : Between CreateWin1() and Repeat put

Global Timer=CreateTimer(1000)

Change Select WaitEvent(1000) back to

Select WaitEvent()

and after Case $803:End and before End Select put

Case $4001

A $4001 event will occur every time your timer ticks over (every second)... So you will want to put your Seconds counter code under that.


hub(Posted 2003) [#6]
Many thanks for your answer Toby !


SDF_of_BC(Posted 2003) [#7]
Thanks I the same problem! :)


Hotcakes(Posted 2003) [#8]
Just a couple of little things if you decide to start using Timers a lot... obviously if you have more than one Timer in your code you will need to figure out which one has caused a $4001 Event, this is done by using EventData or something, look it up in the helpfiles ;] Also when you create a Timer it starts ticking straight away... So it's always best to create them -right before- your main loop for complete accuracy... if you create them too early they have the chance to start ticking over while you are loading images/doing other stuff =]


SDF_of_BC(Posted 2003) [#9]
well the timer would have a handel, so in that case 'eventsource()' might be better!


Hotcakes(Posted 2003) [#10]
yeh, that. =]


SDF_of_BC(Posted 2003) [#11]
neat.