Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 664
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Post by Kurzer »

I want to fire an event with PostEvent.

Code: Select all

PostEvent(Event [, Window, Object [, Type [, Data]])
A data value is to be passed (last parameter), but no window, no object and no EventType.

Can I use #PB_Ignore for this?

Code: Select all

PostEvent(#MyCustomEvent, #PB_Ignore, #PB_Ignore, #PB_Ignore, 300)
Or does it make no difference at all, because PureBasic doesn't care about these values at all? The event should be sent to all windows and I don't want that it is not sent to all windows by specifying a wrong constant at the parameter Window, Object and Type.

Markus
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2023: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Post by mk-soft »

Yes ;)
You can use all parameters as long as you structure your evaluation of the WaitWindowEvent correctly.
That means, always first evaluate the event (e.g. #PB_Event_CloseWindow) and then the meant window (EventWindow).

Code: Select all

;-TOP

Enumeration #PB_Event_FirstCustomValue
  #MyEvent_Data
EndEnumeration

Enumeration Windows
  #Main
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    
    Debug "Constant #PB_Ignore = " + #PB_Ignore
    
    PostEvent(#MyEvent_Data, #PB_Ignore, #PB_Ignore, #PB_Ignore, 300)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
        Case #MyEvent_Data
          Debug "Window = " + EventWindow()
          Debug "Gadget = " + EventGadget()
          Debug "Type   = " + EventType()
          Debug "Data   = " + EventData()
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
Last edited by mk-soft on Sat Oct 03, 2020 2:20 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 664
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Post by Kurzer »

Great, many thanks, mk-soft.
You put a lot of effort and wrote an example. Image
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2023: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Post by mk-soft »

The PostEvent function does not trigger any internal actions. It only adds the message in the event buffer, which you then evaluate after WaitWindowEvent.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Can I use #PB_Ignore for 'empty' PostEvent Parameters?

Post by mk-soft »

Here is the proof how PostEvent works and the truth about the function EventTimer :wink:

Code: Select all

;-TOP

Enumeration #PB_Event_FirstCustomValue
  #MyEvent_Data
EndEnumeration

Enumeration Windows
  #Main
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    
    Debug "Constant #PB_Ignore = " + #PB_Ignore
    Debug "----------------------------------"
    
    PostEvent(#MyEvent_Data, #PB_Ignore, #PB_Ignore, #PB_Ignore, 300)
    
    PostEvent(#PB_Event_Gadget, 1, 10, 100, 1000)
    
    AddWindowTimer(#Main, 999, 1000)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
        Case #PB_Event_Gadget
          Debug "#PB_Event_Gadget"
          Debug "Window          = " + EventWindow()
          Debug "Gadget (Object) = " + EventGadget()
          Debug "Type            = " + EventType()
          Debug "Data            = " + EventData()
          Debug "Timer  (Object) = " + EventTimer()
          Debug "----------------------------------"
          
        Case #PB_Event_Timer
          Debug "#PB_Event_Timer"
          Debug "Window          = " + EventWindow()
          Debug "Gadget (Object) = " + EventGadget()
          Debug "Type            = " + EventType()
          Debug "Data            = " + EventData()
          Debug "Timer  (Object) = " + EventTimer()
          Debug "----------------------------------"
          RemoveWindowTimer(#Main, 999)
          
        Case #MyEvent_Data
          Debug "#MyEvent_Data"
          Debug "Window          = " + EventWindow()
          Debug "Gadget (Object) = " + EventGadget()
          Debug "Type            = " + EventType()
          Debug "Data            = " + EventData()
          Debug "Timer  (Object) = " + EventTimer()
          Debug "----------------------------------"
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply