Page 1 of 1

PB5.50b1; PostEvent;

Posted: Tue Jun 28, 2016 1:07 pm
by HanPBF
Hello PB forum!

Maybe a silly question...
Does PostEvent only works if a window is open?

With OpenConsole I get no custom events captured...

Tried to map the websockets callback to events and saw, no event was captured until I opened a window...

Desired behaviour?

From the PB example:

Code: Select all

; All our custom events
  Enumeration #PB_Event_FirstCustomValue
    #EventBeginProcessing
    #EventProcessingFinished
  EndEnumeration
  
  
  Procedure Thread(Value)
    PostEvent(#EventBeginProcessing, 1, 2)
    
    Delay(3000)
    
    PostEvent(#EventProcessingFinished, 1, 2)
  EndProcedure
  
  Procedure onBeginProcessing()
  	Debug "Thread begin processing "
  EndProcedure
  
  procedure onProcessingFinished()
  	debug "Thread processing finished"
  EndProcedure
  
  OpenWindow(0, 200, 200, 100, 100, "PostEvent", #PB_Window_Invisible) ; no window, no WaitWindowEvent() -> o.k.
  
  CreateThread(@Thread(), 0)
  
  bindevent(#EventBeginProcessing, @onBeginProcessing())
  bindevent(#EventProcessingFinished, @onProcessingFinished())
  
  
  if OpenConsole("Test")  
  	repeat
  		delay(100)
  		Event = WaitWindowEvent() ; -> no WaitWindowEvent(), no events at all?
  	forever  	
  endif
  
  
;   Repeat
;     Event = WaitWindowEvent()        
;   Until Event = #PB_Event_CloseWindow

Thanks!

Re: PB5.50b1; PostEvent;

Posted: Tue Jun 28, 2016 1:55 pm
by Fred
Yes, you need a window. It's (Wait)WindowEvent() which runs the event loop and trigger the event callback. BTW, you should remove the Delay() when using an event loop.

Re: PB5.50b1; PostEvent;

Posted: Tue Jun 28, 2016 2:41 pm
by HanPBF
Thanks a lot for the info!

"removing delay()" -> sure; that was used to handle websocket callback
Due to the events no more needed.

I will do this with an invisible window in the future which should also work in not-logged-in-mode at windows server site(?)...


Thanks,
regards!

Re: PB5.50b1; PostEvent;

Posted: Tue Jun 28, 2016 2:50 pm
by Fred
it should

Re: PB5.50b1; PostEvent;

Posted: Mon Jul 11, 2016 7:03 pm
by netmaestro
A message-only window would be a good choice for that:
MSDN wrote:Message-Only Windows
A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.
To create a message-only window, specify the HWND_MESSAGE constant or a handle to an existing message-only window in the hWndParent parameter of the CreateWindowEx function. You can also change an existing window to a message-only window by specifying HWND_MESSAGE in the hWndNewParent parameter of the SetParent function.
Small demo (note no visible window and nothing on the taskbar):

Code: Select all

#HWND_MESSAGE = -3

OpenWindow(0,0,0,0,0,"")
SetParent_(WindowID(0), #HWND_MESSAGE)
AddWindowTimer(0,1,1000)

count=0
Repeat
  EventID = WaitWindowEvent()
  Select EventID
    Case #PB_Event_Timer
      Debug "ding"
      count+1
  EndSelect
Until count >= 6
Debug "Ended"

Re: PB5.50b1; PostEvent;

Posted: Wed Jul 13, 2016 10:09 am
by HanPBF
Thanks a lot for the tip!!!