Refresh problem
BlitzPlus Forums/BlitzPlus Programming/Refresh problem
| ||
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 |
| ||
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. |
| ||
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. |
| ||
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 |
| ||
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. |
| ||
Many thanks for your answer Toby ! |
| ||
Thanks I the same problem! :) |
| ||
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 =] |
| ||
well the timer would have a handel, so in that case 'eventsource()' might be better! |
| ||
yeh, that. =] |
| ||
neat. |