WaitWindowEvent - TimeOut and SetTimer

Just starting out? Need help? Post your questions and find answers here.
Sven
User
User
Posts: 20
Joined: Sat Mar 11, 2006 6:46 pm

WaitWindowEvent - TimeOut and SetTimer

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Well, of course there is no timeout anymore. You are getting lots of WM_TIMER messages from WaitWindowEvent().
quidquid Latine dictum sit altum videtur
Sven
User
User
Posts: 20
Joined: Sat Mar 11, 2006 6:46 pm

Post 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
maw

Post 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..
Sven
User
User
Posts: 20
Joined: Sat Mar 11, 2006 6:46 pm

Post 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
Post Reply