Page 1 of 2

Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 10:43 am
by infratec
Like in NetworkServerEvent() you should be able to add the Window as parameter.
Then you can handle different windows in different event loops.

This makes sense if you need a hidden window as callback receiver (like for playing MIDI in windows)
Then you can handle this without disturbing the rest.

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 11:40 am
by Caronte3D
+1
Also useful if like on my case you have a window inside a dll (not a good practice, I know, but works nice on Windows) 8)

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 11:56 am
by AZJIO
EventWindow()?

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 12:59 pm
by mk-soft
AZJIO wrote: Mon Jun 09, 2025 11:56 amEventWindow()?
After a WindowEvent() or WaitWindowEvent() function, use this function to determine on which window the event has occurred.
Thus, one can separate the further event processing.

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 1:29 pm
by Quin
+1. This would be super useful.

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 1:43 pm
by AZJIO
This will simply insert the following construction into your code

Code: Select all

Bool(WaitWindowEvent() And EventWindow() = #Wim1)

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 1:47 pm
by Quin
AZJIO wrote: Mon Jun 09, 2025 1:43 pm This will simply insert the following construction into your code

Code: Select all

Bool(WaitWindowEvent() And EventWindow() = #Wim1)
...Okay?
What is your point exactly?
Being able to use a bool expression to do the same thing does not mean the feature shouldn't be asked for/implemented... :mrgreen:

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 2:44 pm
by infratec
AZJIO wrote: Mon Jun 09, 2025 1:43 pm This will simply insert the following construction into your code

Code: Select all

Bool(WaitWindowEvent() And EventWindow() = #Wim1)
That does not work. You get the event already by calling WaitWindowEvent().
So if it does not fit EventWindow(), you lost this event.

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Mon Jun 09, 2025 9:14 pm
by infratec
And BindEvent() is also not possible.
It does not work for #MM_MCINOTIFY for example.
So I can not open a hidden window and proccess the MIDI CallBack in the background.

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Tue Jun 10, 2025 4:12 am
by AZJIO

Code: Select all

Procedure WaitWindowEvent2(wnd_id)
	Protected Result
	If EventWindow() = wnd_id
		Result = WaitWindowEvent()
	EndIf
    ProcedureReturn Result
EndProcedure

Event = WaitWindowEvent2(#Wim1)

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Tue Jun 10, 2025 6:49 am
by infratec
AZJIO wrote: Tue Jun 10, 2025 4:12 am

Code: Select all

Procedure WaitWindowEvent2(wnd_id)
	Protected Result
	If EventWindow() = wnd_id
		Result = WaitWindowEvent()
	EndIf
    ProcedureReturn Result
EndProcedure

Event = WaitWindowEvent2(#Wim1)
You can call EventWindow first when WindowEvent or WaitWinowEvent returns.
So you loose one event if it is not for your specified window.

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Tue Jun 10, 2025 8:49 am
by AZJIO
infratec wrote: Tue Jun 10, 2025 6:49 am You can call EventWindow first when WindowEvent or WaitWinowEvent returns.
If you call WindowEvent() and WaitWinowEvent(), which both capture the event, you can skip it. But EventWindow() does not capture the event, but gets the window in which the event occurred. The help for EventWindow() says that the function should be called after capturing events.

Code: Select all

Procedure WaitWindowEvent2(wnd_id)
	Protected Result
	Result = WaitWindowEvent()
	If EventWindow() <> wnd_id
		Result = 0
	EndIf
    ProcedureReturn Result
EndProcedure


Event = WaitWindowEvent2(#Wim1)

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Tue Jun 10, 2025 9:35 am
by Caronte3D
I think infratec is correct, the WaitWindowEvent() in your example consume an event so if it's not from the correct window, the event is lost, not repeated on the other event loop.

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Tue Jun 10, 2025 10:28 am
by mk-soft
There should only ever be one call to (Wait)WindowEvent().
In this loop, you can split the events depending on the window to be processed further
The window number is also entered for each valid event.

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#Version = "v1.01.1"

Enumeration Windows
  #Main
  #Diaglog1
  #HideWindow
EndEnumeration

Enumeration Menus
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuExitApplication
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Global ExitApplication

; ----

Procedure DoEventsMain(Event)
  
  Select Event
    Case #PB_Event_CloseWindow
      ExitApplication = #True
      
    Case #PB_Event_Menu
      Select EventMenu()
        Case #MainMenuExitApplication
          ExitApplication = #True
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget()
          
      EndSelect
      
  EndSelect
  
EndProcedure

Procedure DoEventsDialog1(Event)
  
  Select Event
    Case #PB_Event_CloseWindow
      ; TODO
      CloseWindow(#Diaglog1)
      
    Case #PB_Event_Menu
      Select EventMenu()
          
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget()
          
      EndSelect
      
  EndSelect
  
EndProcedure

Procedure DoEventsHideWindow(Event)
  
  Select Event
    Case #PB_Event_CloseWindow
      ; TODO
      CloseWindow(#HideWindow)
      
    Case #PB_Event_Menu
      Select EventMenu()
          
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget()
          
      EndSelect
      
    Case #PB_Event_Timer
      Select EventTimer()
        Case 1
          Debug "Timer"
          
      EndSelect
      
  EndSelect
  
EndProcedure

; ----

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  
EndProcedure

; ----

Procedure OpenHideWindow()
  If OpenWindow(#HideWindow, 0, 0, 0, 0, "EventTimer", #PB_Window_Invisible, WindowID(#Main))
    AddWindowTimer(#HideWindow, 1, 1000)    
  EndIf
EndProcedure

Procedure Main()
  Protected dx, dy

  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("File")
    MenuItem(#MainMenuExitApplication, "E&xit")
    ; For Mac
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      If Not IsMenu(#MainMenu)
        CreateMenu(#MainMenu, WindowID(#Main))
      EndIf
      MenuItem(#PB_Menu_About, "")
      MenuItem(#PB_Menu_Preferences, "")
    CompilerEndIf
    ; StatusBar  
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    StatusBarText(#MainStatusBar, 0, " " + #Version)
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    
    ; Bind events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    OpenHideWindow()
    
    ; Main loop
    Repeat
      Event = WaitWindowEvent()
      Select EventWindow()
        Case #Main
          DoEventsMain(Event)
        Case #Diaglog1
          DoEventsDialog1(Event)
        Case #HideWindow
          DoEventsHideWindow(Event)
          
      EndSelect
      
    Until ExitApplication
    
  EndIf
  
EndProcedure : Main()

Re: Additional parameter for WindowEvent and WaitWindowEvent

Posted: Tue Jun 10, 2025 10:28 am
by Fred
I don't think it will be possible to do that, as there is a single queue for event, so if you want to filter for a specific window, all other events needs to be stored somewhere and it will create issues for sure with callbacks. @mk-soft just shown the right way to do it.