Page 1 of 1

WaitWindowEvent( )

Posted: Wed Oct 09, 2024 6:13 pm
by mestnyi
Is there a difference between them?

Code: Select all

WaitWindowEvent( )
WaitWindowEvent(0)

Re: WaitWindowEvent( )

Posted: Wed Oct 09, 2024 6:24 pm
by mk-soft
Not good.
With WaitWindowEvent(0), i.e. timeout of 0 milliseconds, the event loop is constantly running and 100% processor power is consumed.

Code: Select all

;-TOP

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent(0) ; <-- Never use 0
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
      
      c + 1
      Debug c
      
    ForEver
    
  EndIf
  
EndProcedure : Main()

Re: WaitWindowEvent( )

Posted: Wed Oct 09, 2024 6:41 pm
by mestnyi
viewtopic.php?p=624395#p624395
I had an example that receives a mouse click event anywhere, it turned out that it does not work if the "WaitWindowEvent()" function does not specify a timeout.