EventWindow() Undocumented feature

Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

EventWindow() Undocumented feature

Post 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.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: EventWindow() Undocumented feature

Post 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:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

Re: EventWindow() Undocumented feature

Post 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.
Think Unicode!
User avatar
Demivec
Addict
Addict
Posts: 4259
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: EventWindow() Undocumented feature

Post 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.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: EventWindow() Undocumented feature

Post 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.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
Demivec
Addict
Addict
Posts: 4259
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: EventWindow() Undocumented feature

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: EventWindow() Undocumented feature

Post 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:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: EventWindow() Undocumented feature

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: EventWindow() Undocumented feature

Post 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:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
fromVB
User
User
Posts: 82
Joined: Sun Jul 29, 2012 2:27 am

Re: EventWindow() Undocumented feature

Post 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?
User avatar
Demivec
Addict
Addict
Posts: 4259
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: EventWindow() Undocumented feature

Post 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. :)
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: EventWindow() Undocumented feature

Post 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:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Locked