What is PostEvent() window # without optional paramater

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 536
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

What is PostEvent() window # without optional paramater

Post by BasicallyPure »

If PostEvent(Event [, Window, Object [, Type [, Data]]]) is used without the optional Window parameter
what is the Window number returned by EventWindow()?

The help does not specify what this will be but I always assumed it was the current window's number.
It appears that EventWindow() always returns 0 if PostEvent() is used without the optional window parameter.

Code: Select all

OpenWindow(10,0,0,250,200, "PostEvent & EventWindow", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

Repeat
   Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
         Break
      Case #PB_Event_RightClick
         PostEvent(#PB_Event_LeftClick) ;<-- this way generates EventWindow() = 0
         ;PostEvent(#PB_Event_LeftClick,10,#PB_Ignore) ;<-- this way works
      Case #PB_Event_LeftClick
         Ev_Window = EventWindow()
         Debug "Event_LeftClick : EventWindow = " + Ev_Window
         If Ev_Window <> 10 And Ev_Window <> -1
            Debug "why? EventWindow() must be 10 or -1 "
         EndIf
         
   EndSelect
ForEver
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: What is PostEvent() window # without optional paramater

Post by Fred »

No, it won't be the current window, as there is no current window (or you mean active window ?). If you don't specify the parameter, it will be 0. May be it would be better to use #PB_All as default value. I will move to feature and request for further inspection.
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 536
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: What is PostEvent() window # without optional paramater

Post by BasicallyPure »

Thank you for your response Fred.
Fred wrote:No, it won't be the current window, as there is no current window (or you mean active window ?).
Yes I mean active window.
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: What is PostEvent() window # without optional paramater

Post by GPI »

Maybe a new konstant #pb_windowid_broadcast would be a solution.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: What is PostEvent() window # without optional paramater

Post by mestnyi »

May be it would be better to use #PB_All as default value
That would be correct.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: What is PostEvent() window # without optional paramater

Post by kenmo »

Fred wrote:May be it would be better to use #PB_All as default value. I will move to feature and request for further inspection.
Maybe another named constant, with the same value of -1.

#PB_All might be confusing: user might think that #PB_All posts a copy of the event to ALL opened windows.
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: What is PostEvent() window # without optional paramater

Post by Danilo »

kenmo wrote:Maybe another named constant, with the same value of -1.

#PB_All might be confusing: user might think that #PB_All posts a copy of the event to ALL opened windows.
-1 is already used internally for non-valid events, so I think it's good to use -1 there as well. It means no Window number is specified,
and EventWindow() number is not valid / can't be used.

#PB_All would indeed indicate that it is for all Windows. If that would be the case, all BindEvent() callbacks for all Windows
must be called for that specific message.
IMO if you don't specify a Window, it is not for a specific Window, so just -1 should be fine. Or #PB_Ignore / #PB_Unknown / #PB_Unspecified
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: What is PostEvent() window # without optional paramater

Post by mestnyi »

-1 is already used internally for non-valid events, so I think it's good to use -1 there as well
I agree
all BindEvent() callbacks for all Windows
must be called for that specific message.
That's not quite understand, but if you say you want to change.
That is not to call for all windows and just for a specific window.
I say do not touch because it works very well. :)

Code: Select all

Procedure Event( ) 
  Debug "Event_LeftClick "+EventWindow()
EndProcedure

OpenWindow(1, 200, 100, 150, 100, "Window_1")
OpenWindow(2, 400, 100, 150, 100, "Window_2")

BindEvent(#PB_Event_LeftClick, @Event()) 

While WaitWindowEvent() ! #PB_Event_CloseWindow :Wend
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: What is PostEvent() window # without optional paramater

Post by mestnyi »

Maybe this question was answered, but I did not find it.
So that's why? so

Code: Select all

PostEvent (Event[, Window, Object]...)

not so

Code: Select all

PostEvent (Event[, Window[, Object]]...)
Post Reply