PB5.50b1; PostEvent;

Windows specific forum
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

PB5.50b1; PostEvent;

Post 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!
Fred
Administrator
Administrator
Posts: 18225
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB5.50b1; PostEvent;

Post 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.
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: PB5.50b1; PostEvent;

Post 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!
Fred
Administrator
Administrator
Posts: 18225
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB5.50b1; PostEvent;

Post by Fred »

it should
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: PB5.50b1; PostEvent;

Post 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"
BERESHEIT
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: PB5.50b1; PostEvent;

Post by HanPBF »

Thanks a lot for the tip!!!
Post Reply