RE: Let's try that again --was RE: CText
- Posted by Brian Broker <bkb at cnw.com> Dec 04, 2001
- 389 views
For those following this thread, I've already replied privately to Evan but here was my reply. Evan, given your test examples I can offer the following advice: Rule number one for writing windows programs: Avoid busy-waiting if at all possible. What's probably happening in the second example is the following: procedure Display gets called which queues a message to show the CText. This message doesn't seem to get processed until after your Activation routine. But you are also hiding your window during Activation so when the routine is done, we process both messages at once. Show/Hide in succession looks like it's never shown. Here's how I would re-write the second example to avoid busy waiting (the empty for-loop is a delay which is dependent on system speed and pushes CPU utilization to max. That's not good.) Instead, try something like this: -- test2.exw -- include win32lib.ew constant Win = create(Window, "Window", 0, 0, 0, 600, 600, Normal), myCText = create(CText, "This is CText", Win, 250, 200, 100, 15, 0) sequence seq1 seq1= {0,0,5,0,0} integer int1, d int1 = 5 setVisible(myCText, False) procedure Display() d = find(int1,seq1) if d then setVisible(myCText, True) end if end procedure procedure onTimer_Win( atom id ) if id = 1 then killTimer( Win, id ) -- stop timer setVisible(myCText, False) -- show CText end if end procedure onTimer[Win] = routine_id( "onTimer_Win" ) procedure ClearText() Display() setTimer( Win, 1, 3000 ) -- 3 second delay end procedure onActivate[Win] = routine_id( "ClearText" ) WinMain(Win, Normal) -- end program -- Hope this helps, -- Brian Evan Marshall wrote: > This works: > ------------------------------ > include win32lib.ew > > constant > Win = create(Window, "Window", 0, 0, 0, 600, 600, Normal), > myCText = create(CText, "This is CText", Win, 250, 200, 100, 15, 0) > > setVisible(myCText, False) > > procedure Display() > setVisible(myCText, True) > end procedure > onActivate[Win] = routine_id( "Display" ) > > procedure ClearText() > setVisible(myCText, False) > end procedure > onClick[Win] = routine_id( "ClearText" ) > > WinMain(Win, Normal) > > This doesn't: > -------------------- > > include win32lib.ew > > constant > Win = create(Window, "Window", 0, 0, 0, 600, 600, Normal), > myCText = create(CText, "This is CText", Win, 250, 200, 100, 15, 0) > > setVisible(myCText, False) > > procedure Display() > setVisible(myCText, True) > end procedure > > procedure ClearText() > Display() > for t = 1 to 100000000 do end for > setVisible(myCText, False) > end procedure > onActivate[Win] = routine_id( "ClearText" ) > > WinMain(Win, Normal)