bug ?, WaitWindowEvent(5333),why n fast to 5 when Waiting

Just starting out? Need help? Post your questions and find answers here.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

bug ?, WaitWindowEvent(5333),why n fast to 5 when Waiting

Post by gurj »

bug ?, WaitWindowEvent(4333),why n fast to 5 when Waiting

Code: Select all

If OpenWindow(0,0,0,300,200,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)

 Repeat:ev=WaitWindowEvent(4333):Select ev
   Case #PB_Event_CloseWindow:Quit = 1
    Case 0:Debug n:n+1
 EndSelect:Until Quit = 1
EndIf:End
my pb for chinese:
http://ataorj.ys168.com
User avatar
gurj
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: bug ?, WaitWindowEvent(5333),why n fast to 5 when Waitin

Post by gurj »

this not fast to 5:

Code: Select all

If OpenWindow(0,0,0,300,200,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
 
 For a=1 To 10
  WaitWindowEvent(20)
 Next

 Repeat:ev=WaitWindowEvent(4333):Select ev
   Case #PB_Event_CloseWindow:Quit = 1
    Case 0:Debug n:n+1
 EndSelect:Until Quit = 1
EndIf:End
my pb for chinese:
http://ataorj.ys168.com
User avatar
Michael Vogel
Addict
Addict
Posts: 2680
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: bug ?, WaitWindowEvent(5333),why n fast to 5 when Waitin

Post by Michael Vogel »

Purebasic will get some event messages because of creating a window, so if needed to filter them, you may to ignore them before your event handling (that's what you've done in your second example).

I am not sure what you want to do, but maybe setting a timer could help? You may also play around with different versions, so you can remove the semicolons in the following example, line [A] to see the difference when using an timer, is the same filtering you did already, [C] filters some mouse actions and [D] will show additional events, when a new gadget will be inserted (after doing a mouse click)...

Code: Select all

OpenWindow(0,0,0,300,200,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)

; AddWindowTimer(0,0,1500);						[ A ]

For i=0 To 9
	; WindowEvent();							[ B ]
Next i

t=ElapsedMilliseconds()

Repeat
	ev=WaitWindowEvent(2000); 					also try 1000 here when the timer is active !
	Select ev

	;Case #WM_MOUSEMOVE;						[ C ]
	;Case #WM_LBUTTONDOWN;					[ C ]
	;Case #WM_LBUTTONUP;						[ C ]
		; ButtonGadget(1,10,10,100,100,"Test");	[ D ]

	Case #PB_Event_CloseWindow
		Quit = 1

	Case #PB_Event_Timer
		m+1
		Debug "m: "+Str(m)+" @ "+Str(ElapsedMilliseconds()-t)

	Case 0
		n+1
		Debug "n: "+Str(n)+" @ "+Str(ElapsedMilliseconds()-t)

	Default
		Debug "event: 0x"+Hex(ev)

	EndSelect

Until Quit = 1
User avatar
gurj
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: bug ?, WaitWindowEvent(5333),why n fast to 5 when Waitin

Post by gurj »

thanks Michael Vogel.

I want to ' end exe ', if WaitWindowEvent(4333) Waited 4333ms
I want not to use timer here.
so maybe WaitWindowEvent(4333) has bug, because each n least must 4333ms ,but n fast to 5 at start.

for filter this bug , also may use timer as this :

Code: Select all

If OpenWindow(0,0,0,300,200,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
 ;If exe sleeping 4000ms , To End :
 Repeat:ev=WaitWindowEvent(4000):Select ev
   Case #PB_Event_CloseWindow:Quit = 1
    Case #PB_Event_Timer:Wait=1:Debug 0:RemoveWindowTimer(0,0)
    Case 0:If Wait=1:Debug 1:End:Else:AddWindowTimer(0,0,50):EndIf
 EndSelect:Until Quit = 1
EndIf:End
my pb for chinese:
http://ataorj.ys168.com
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: bug ?, WaitWindowEvent(5333),why n fast to 5 when Waitin

Post by Olliv »

Code: Select all

WaitWindowEvent(1 second)
will wait one second or an event before.

Code: Select all

WaitWindowEvent(1 year)
will wait one year or an event before.
Then, for this last way, if an event occurs before one year of waiting, what is over (after and before WaitWE() statement inside the main loop) is executed and WaitWE() will wait again one year or a new event before.

Globally, the delay argument inside WaitWE() is a maximum duration.

If you want to execute a procedure on a set delay (not on a maximum delay, just on a set delay), you should use the two functions before the main loop :

AddWindowTimer()
(here you set window id, timer id and duration in milliseconds).

BindEvent()
(here you set the event code - #pb_event_timer - , the window id and the procedure address to be executed everytime the time is elapsed).
User avatar
gurj
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: bug ?, WaitWindowEvent(5333),why n fast to 5 when Waitin

Post by gurj »

thanks Olliv.
my pb for chinese:
http://ataorj.ys168.com
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: bug ?, WaitWindowEvent(5333),why n fast to 5 when Waitin

Post by Olliv »

Also, let's imagine a real using of the argument of WaitWindowEvent()...
Remove '16' and test again...

Code: Select all

Duration = 5000 ; 5000ms countdown

OpenWindow(0, 0, 0, 200, 200, "")
ButtonGadget(1, 10, 10, 100, 30, "START")
ButtonGadget(2, 10, 50, 100, 30, "STOP")

Repeat
 Lap = ElapsedMilliseconds()
 Ev = WaitWindowEvent(16)
 Button = EventGadget()
 If Lap1
  Lap0 = Lap1 - Lap
  SetWindowTitle(0, Str(Lap0) )
  If Button = 2
   Lap1 = 0
  EndIf
  If Lap0 <= 0
   End
  EndIf
 Else
  If Button = 1
   Lap1 = Lap + Duration
  EndIf
 EndIf
Until Ev = #PB_Event_CloseWindow
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: bug ?, WaitWindowEvent(5333),why n fast to 5 when Waitin

Post by Olliv »

('16' value forces WaitWindowEvent() to execute main loop, every 16 ms.

This allows you to see a right countdown.
If nothing instead, countdown is not updated as wanted.)
Post Reply