Page 1 of 1

EventWindow() Undocumented feature

Posted: Fri Oct 23, 2015 5:13 am
by collectordave
The EventWindow() function returns erronous results until after a valid PB event has occurred. The WindowEvent() and WaitWindowEvent() return all events whether valid PB events or not.

Can the documentation be amended to show this. A simple amedment such as:-

Description

After a WindowEvent() or WaitWindowEvent() function returns a valid PB event, use this function to determine on which window the event has occurred.

Re: EventWindow() Undocumented feature

Posted: Fri Oct 23, 2015 2:02 pm
by TI-994A
PureBasic Manual - EventWindow()

Description
After a WindowEvent() or WaitWindowEvent() function, use this function to determine on which window the event has occurred.

Return value
The window number on which the event has occurred.
The manual has clearly indicated that the function is to be used only following an event.

No ambiguity; no bug. :wink:

Re: EventWindow() Undocumented feature

Posted: Fri Oct 23, 2015 3:08 pm
by ElementE
collectordave wrote:
The WindowEvent() and WaitWindowEvent() return all events whether valid PB events or not.
Thus a PureBasic program should act only on Official PB events in order to work properly.

Re: EventWindow() Undocumented feature

Posted: Fri Oct 23, 2015 4:13 pm
by Demivec
PB Manual/WindowEvent() wrote:To get the window number in which the event occurred, use the EventWindow() function.

Possible Events are :

#PB_Event_Menu : a menu has been selected
#PB_Event_Gadget : a gadget has been pushed
#PB_Event_SysTray : an icon in the systray zone was clicked
#PB_Event_Timer : a timer has reached its timeout
#PB_Event_CloseWindow : the window close gadget has been pushed
#PB_Event_Repaint : the window content has been destroyed and must be repainted (useful for 2D graphics operations)
#PB_Event_SizeWindow : the window has been resized
#PB_Event_MoveWindow : the window has been moved
#PB_Event_MinimizeWindow : the window has been minimized
#PB_Event_MaximizeWindow : the window has been maximized
#PB_Event_RestoreWindow : the window has been restored to normal size (either from a minimum or maximum size)
#PB_Event_ActivateWindow : the window has been activated (got the focus)
#PB_Event_DeactivateWindow: the window has been deactivated (lost the focus)
#PB_Event_WindowDrop : a Drag & Drop operation was finished on a window
#PB_Event_GadgetDrop : a Drag & Drop operation was finished on a gadget
#PB_Event_RightClick : a right mouse button click has occurred on the window. This can be useful to display a popup menu
#PB_Event_LeftClick : a left mouse button click has occurred on the window
#PB_Event_LeftDoubleClick : a left mouse button double-click has occurred on the window
The possible 'correct' events are listed. In addition to these are custom events posted with PostEvent().


Notwistanding the fact that the manual already lists these things I am in favor of a more explicit statement such as the one that you suggested. You are not the first person to become confused by the 'natural order' to be followed in using theinformation functions for events.

Re: EventWindow() Undocumented feature

Posted: Sat Oct 24, 2015 5:52 am
by collectordave
TI-994A wrote
The manual has clearly indicated that the function is to be used only following an event.
The manual clearly states that, agreed. However at no point does it state that the value returned by the function is only valid after an official PB event.
ElementE wrote
Thus a PureBasic program should act only on Official PB events in order to work properly.
Just being a newbie to this I thought the reason your program acted only on Official PB events was to preserve the cross platform compatibility of the code, one of the real strengths of PB. The question then comes down to which events are Official PB events. The waitwindowevent() etc makes no distinction.

Thanks for the list Demivec. I have noticed that I am not the first to become confused with this. Those few extra words would make it quite clear so when posting for help on a problem, as I did, could then be answered quite simply by saying you are reacting to non Official PB events and not following the manual. Just giving me a DOH! moment and saving hours of fruitless work.

Can I assume that PostEvent() is something a more experienced programmer would use? Just asking as I have started converting a program from VB to PB which uses over forty windows/forms and would really enjoy not getting bitten again.

Re: EventWindow() Undocumented feature

Posted: Sat Oct 24, 2015 6:41 am
by Demivec
collectordave wrote:Can I assume that PostEvent() is something a more experienced programmer would use? Just asking as I have started converting a program from VB to PB which uses over forty windows/forms and would really enjoy not getting bitten again.
Yes, it is in the 'more advanced' category, but still simpler than pointers :) .

It is used to send custom events to the PB message loop (or 'BindEvent' procedures). A possible use is as a communication method between threads to allow progressbars to update and such. It is strictly for communicating a custom event and is not acted on in any way by the OS. Check out its entry in the user manual for some sample code to illustrate its uses. Chances are you won't need it, but you never know.

Re: EventWindow() Undocumented feature

Posted: Sat Oct 24, 2015 6:57 am
by TI-994A
collectordave wrote:
TI-994A wrote:The manual has clearly indicated that the function is to be used only following an event.
The manual clearly states that, agreed. However at no point does it state that the value returned by the function is only valid after an official PB event.
It's PureBasic, so logically, it only handles its prescribed events.

Once you stray off the reservation, into the lowlands of OS events, all bets are off, and it's no longer PureBasic's responsibility. Nevertheless, the ability to do so is yet another one of PureBasic's strengths.
collectordave wrote:The question then comes down to which events are Official PB events. The waitwindowevent() etc makes no distinction.
The first rule of programming; GIGO.

Even professional programming languages like C/C++ don't make such distinctions. If you require such hand-holding, you'd be better off with a more managed language; like VB, perhaps.
collectordave wrote:...could then be answered quite simply by saying you are reacting to non Official PB events and not following the manual ... saving hours of fruitless work.
It's very clear by now, that you don't read the manual or the posted answers to your questions.

Stick to the prescribed sequence, as indicated in the manual, and you won't go wrong.
collectordave wrote:...converting a program from VB to PB which uses over forty windows/forms and would really enjoy not getting bitten again.
You will, if you continue to use the big numbers that you love so much as object identifiers. :lol:

Re: EventWindow() Undocumented feature

Posted: Sun Oct 25, 2015 1:11 am
by collectordave
collectordave wrote
The EventWindow() function returns erronous results until after a valid PB event has occurred. The WindowEvent() and WaitWindowEvent() return all events whether valid PB events or not.

Can the documentation be amended to show this. A simple amedment such as:-

Description

After a WindowEvent() or WaitWindowEvent() function returns a valid PB event, use this function to determine on which window the event has occurred.
TI-994A wrote the above

Sorry but I do not see the relevance of your post to this topic or the opening statements

Re: EventWindow() Undocumented feature

Posted: Sun Oct 25, 2015 1:55 am
by TI-994A
collectordave wrote:Sorry but I do not see the relevance of your post to this topic or the opening statements
I'm sure you don't; you never do. :lol:

Re: EventWindow() Undocumented feature

Posted: Sun Oct 25, 2015 3:21 am
by fromVB
collectordave wrote:TI-994A wrote the above

Sorry but I do not see the relevance of your post to this topic or the opening statements
Hello cd. From what I understand, he is saying that when the manual says "event" it is talking about PB events. Why should it be talking about events that PB does not support? You said that it should mention "official PB event" which is not necessary.

"GIGO" means garbage in garbage out. You said that WaitWindowEvent makes no distinction but it is the coders responsibility to make sure that only the right data is processed. GIGO!

Finally about no one telling you about official PB events - he did -> http://www.purebasic.fr/english/viewtop ... 29#p474929

@TI-994A: Hope I got it right. What "big numbers" are you talking about?

Re: EventWindow() Undocumented feature

Posted: Sun Oct 25, 2015 4:12 am
by Demivec
fromVB wrote:@TI-994A: Hope I got it right. What "big numbers" are you talking about?
@fromVB: I'll sneak in and respond before TI-994A gets a chance. He means that in examples that collectordave has posted that collectordave uses high gadget or window numbers such as 1000 or 1001 when his example only has 2 of the item in question. collectordave doesn't realize that PB is reserving space for the 1000 (0 through 999) items that come before those numbers also.

I also think it's an important item but just don't think it needed to be emphasized at this point in collectordave's learning or in simple example code. It is hard to know how to do everything right the first time. It's OK to learn it in smaller steps. :)

Re: EventWindow() Undocumented feature

Posted: Sun Oct 25, 2015 5:46 am
by TI-994A
Thanks, fromVB and Demivec. Let's hope it gets through. :wink:
Demivec wrote:I'll sneak in and respond before TI-994A gets a chance. He means that in examples that collectordave has posted that collectordave uses high gadget or window numbers such as 1000 or 1001 when his example only has 2 of the item in question. collectordave doesn't realize that PB is reserving space for the 1000 (0 through 999) items that come before those numbers also.
Beautifully said! Although it has been said before; in some detail:

CodeInBasic Forum - Enumerations
Demivec wrote:I also think it's an important item but just don't think it needed to be emphasized at this point in collectordave's learning or in simple example code. It is hard to know how to do everything right the first time. It's OK to learn it in smaller steps.
With him, I wouldn't chalk it up to novice; it's more like willful indolence. :lol: