Page 1 of 1

WaitWindowEvent - TimeOut and SetTimer

Posted: Wed Apr 12, 2006 10:22 pm
by Sven
Maybe you can tell if this is a bug or not:

Code: Select all

;WaitWindowEvent gives no longer #PB_Event_TimeOut if an API-Timer is running
;with smaller timer value than WaitWindowEvent(TimeOut)
;and the window has lost the focus

;start and focus an other window (debugger...)

#wIDmain = 0
#tIDtimer = 0

#PB_Event_TimeOut = 0

Procedure TimerCallback(WindowID, message, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents
  If message = #WM_TIMER  ;Timer-Intervall
    Debug "TimerCallback " + Str(wParam)
    result = 0
  EndIf  ;message
  ProcedureReturn result 
EndProcedure

If OpenWindow(#wIDmain, 50, 50, 200, 150, "WaitWindowEvent TimeOut")
  SetTimer_(WindowID(#wIDmain), #tIDtimer, 200, @TimerCallback())  ; <= change timer value
  Repeat
    EventID.l = WaitWindowEvent(500)
    If EventID = #PB_Event_TimeOut
      Debug "TimeOut"
    EndIf
  Until EventID = #PB_Event_CloseWindow
EndIf

KillTimer_(WindowID(#wIDmain), #tIDtimer)  ;Timer entfernen
End
Whitout the API-Timer it works, also if the focus is not on the window.

Sven

Posted: Wed Apr 12, 2006 10:49 pm
by freak
Well, of course there is no timeout anymore. You are getting lots of WM_TIMER messages from WaitWindowEvent().

Posted: Thu Apr 13, 2006 10:51 am
by Sven
Of course? Maybe this is a normal behavior, but:

- why do I get no more TimeOuts when the window lost the focus?
- why does the TimerCallback only show the API-Timer-Events? wParam always is the timer-ID set with SetTimer_(), so the WaitWindowEvent()-TimeOut get lost somewhere.

So if one want to have two diffferent timer events (steady display time in statusbar at every 200msec / doing some stuff at every 20msec) this will not work.

Sven

Posted: Thu Apr 13, 2006 11:36 am
by maw
Sven, I think you have misunderstood the WaitWindowEvent(Timeout) function. It will return with #PB_Event_TimeOut if nothing has happend for Timeout milliseconds and only then. That is, if things happen, which they do with your timer, it will never reach the Timeout value.. It's a timeout, not a timer..
So if one want to have two diffferent timer events (steady display time in statusbar at every 200msec / doing some stuff at every 20msec) this will not work.
You then need a separate API-timer for each event..

Posted: Thu Apr 13, 2006 12:02 pm
by Sven
Ok, now I understood. I thought the WaintWindowEvent() responds only on WindowEvents the directly occur to the window, not on CallBack-Events that don't (?) give an event at WaitWindow Event().

Thanks.

Sven