Multiple window problem

Just starting out? Need help? Post your questions and find answers here.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Multiple window problem

Post by TI-994A »

collectordave wrote:Is what I was following and hit the problem allthough it is probably a million to one chance...
Not exactly.

Initially, you checked the event window first:

Code: Select all

Repeat
  event = WaitWindowEvent()
  Select EventWindow()
    Case 1001
      Debug "Wnd2"
Then, you decided to check for unofficial events:

Code: Select all

Repeat
  event = WaitWindowEvent()
  Select Event
    Case  513
      SetGadgetText(String_0,"Left Button Down")
    Case 514
      SetGadgetText(String_0,"Left Button Up")
    Case 515
      SetGadgetText(String_0,"Left Button Double Click")
The manual demonstrates the following:

Code: Select all

Select Event                         ;check the event first
  Case #PB_Event_Gadget                    
    If EventGadget = #Folder         ;then determine the gadget 
      ...
  Case #PB_Event_CloseWindow
    If EventWindow = #WindowFiles    ;or the window
        ...
EndSelect
Stick to the prescribed sequence, as indicated in the manual, and you won't go wrong. :wink:

And another word of advice; avoid using large numbers as object identifiers.
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: Multiple window problem

Post by collectordave »

Sorry but for me it is fixed.

The question now is if reference to this behaviour will be placed in the manual?
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: Multiple window problem

Post by TI-994A »

collectordave wrote:Sorry but for me it is fixed.

The question now is if reference to this behaviour will be placed in the manual?
It was never broke, and it already is in the manual.

But, if you're referring to the example that said posted, then you're out of luck:

Code: Select all

    event = WaitWindowEvent()
    Select event
        Case  #PB_Event_Menu            ,
              #PB_Event_Gadget          ,
              #PB_Event_SysTray         ,
              #PB_Event_Timer           ,
              #PB_Event_CloseWindow     ,
              #PB_Event_Repaint         ,
              #PB_Event_SizeWindow      ,
              #PB_Event_MoveWindow      ,
              #PB_Event_MinimizeWindow  ,
              #PB_Event_MaximizeWindow  ,
              #PB_Event_RestoreWindow   ,
              #PB_Event_ActivateWindow  ,
              #PB_Event_DeactivateWindow,
              #PB_Event_WindowDrop      ,
              #PB_Event_GadgetDrop      ,
              #PB_Event_RightClick      ,
              #PB_Event_LeftClick       ,
              #PB_Event_LeftDoubleClick 
He was simply making the point that events should precede any other processing. Such a bunched-case of arbitrary events is simply illogical.
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: Multiple window problem

Post by collectordave »

It was never broke, and it already is in the manual.
Just looking at manual
EventWindow()

Syntax

WindowNumber = EventWindow()
Description

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

None.
Return value

The window number on which the event has occured.
In some circumstances this does not do what it says in the manual. I have allways believed that a bug is an undocumented feature. Just a few words here such as it only works after an official PB event would suffice to make this not a bug.
Such a bunched-case of arbitrary events is simply illogical.
But it works.
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: Multiple window problem

Post by TI-994A »

collectordave wrote:Just looking at manual
EventWindow()
...use this function to determine on which window the event has occurred.

Return value
The window number on which the event has occurred.
What event do you assume the manual is referring to? :lol:
collectordave wrote:

Code: Select all

    event = WaitWindowEvent()
    Select event
        Case  #PB_Event_Menu            ,
              #PB_Event_Gadget          ,
              #PB_Event_SysTray         ,
              #PB_Event_Timer           ,
              #PB_Event_CloseWindow     ,
              #PB_Event_Repaint         ,
              #PB_Event_SizeWindow      ,
              #PB_Event_MoveWindow      ,
              #PB_Event_MinimizeWindow  ,
              #PB_Event_MaximizeWindow  ,
              #PB_Event_RestoreWindow   ,
              #PB_Event_ActivateWindow  ,
              #PB_Event_DeactivateWindow,
              #PB_Event_WindowDrop      ,
              #PB_Event_GadgetDrop      ,
              #PB_Event_RightClick      ,
              #PB_Event_LeftClick       ,
              #PB_Event_LeftDoubleClick
But it works.
Assume you have a window with a button and a timer; how do you propose handling each of those events?

Sinking in? :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
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Multiple window problem

Post by said »

@collectordave: You are welcome, good that the issue is clear now :D (i went thru similar trouble when starting with PB :( )

I agree with you the doc is not very clear about EventWindow() unlike other sister commands: EventGadget(), EventMenu(), EventTimer(), …. I think the reason for this is very simple:

EventGadget() is only affected and needed after the PB-event #PB_Event_Gadget
EventMenu() is only affected and needed after the PB-event #PB_Event_Menu
and so on …

while EventWindow() is not exclusively related to any one particular PB-event ... So if you want to check only for EventWindow() then you need to check for all possible PB-events (which was the case with your code sample)

Said
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Multiple window problem

Post by collectordave »

Try to take tham all in turn.
Such a bunched-case of arbitrary events is simply illogical.
Far from being arbitrary the list said posted does appear to be the list of official events that windowevent() and waitwindowevent() react to.
What event do you assume the manual is referring to?
From the docs it just says event so i assume that any event that occurs is perfectly OK. If the docs said this is only valid after an official PB event then I would assume that I would need to check for an official PB event before using this function.
Assume you have a window with a button and a timer; how do you propose handling each of those events?

Code: Select all

OpenWindow(1000, 0, 0, 600, 220, "MainWindow", #PB_Window_SystemMenu)
Button_0 = ButtonGadget(#PB_Any, 130, 60, 160, 50, "")
AddWindowTimer(1000, 123, 250)
ProgressBarGadget(0, 10, 10, 380, 20, 0, 100)

Procedure.i CheckEvent(event)
    Select event
        Case  #PB_Event_Menu            ,
              #PB_Event_Gadget          ,
              #PB_Event_SysTray         ,
              #PB_Event_Timer           ,
              #PB_Event_CloseWindow     ,
              #PB_Event_Repaint         ,
              #PB_Event_SizeWindow      ,
              #PB_Event_MoveWindow      ,
              #PB_Event_MinimizeWindow  ,
              #PB_Event_MaximizeWindow  ,
              #PB_Event_RestoreWindow   ,
              #PB_Event_ActivateWindow  ,
              #PB_Event_DeactivateWindow,
              #PB_Event_WindowDrop      ,
              #PB_Event_GadgetDrop      ,
              #PB_Event_RightClick      ,
              #PB_Event_LeftClick       ,
              #PB_Event_LeftDoubleClick
          
          ProcedureReturn #True
            
        Default
          
            ProcedureReturn #False
              
          EndSelect
            
EndProcedure

Repeat
   
    event = WaitWindowEvent()

       If CheckEvent(event) = #True
         If Event = #PB_Event_Timer And EventTimer() = 123
           Value = (Value + 5) % 100
           SetGadgetState(0, Value)
         EndIf  
       
         Select EventGadget()
           Case Button_0
             Debug "buttonpressed"
       
         EndSelect
       EndIf 
Until event = #PB_Event_CloseWindow
That code appears to work; :?

I moved the event check to a procedure to keep the message loop clear.

I was also just checking to see why I got a little confused so looked at this piece of code from the manual

Code: Select all

    ; Wait until a new window or gadget event occurs.
    Event = WaitWindowEvent()
    ; In programs with more than one form, which window did the event occur on.
    EventWindow = EventWindow()
    ; Which gadget did the event occur on.
    EventGadget = EventGadget()
    ; What sort of event occurred.
    EventType = EventType()
Logic to me dictates that i should not do anything I do not have to.

The first thing here, after the event is recieved shows eventwindow() being used then eventgadget() and then eventtype(). As we all now know the events passed on by WaitWindowEvent() are all events not just official PB events. So all three are run everytime an event is recieved even unofficial mousemove events, of which i assume there are thousands. This seems a little illogical.

So being a newbie to this I see the official example using EventWindow() first and assume that is what you do. When things go a little awry you then check the documentation which as you can see offers no help. If when checking it stated "only valid after an official PB event" even as a newbie I would take a closer look and probably ask on the forum how to check for an official PB event.

I suggest the manual and example are modified to explain this.
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: Multiple window problem

Post by TI-994A »

collectordave wrote:Logic to me dictates that i should not do anything I do not have to.
Sound logic; try following it:

Code: Select all

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 220, "MainWindow", wFlags)
ButtonGadget(0, 130, 60, 160, 50, "Button")
ProgressBarGadget(1, 10, 10, 380, 20, 0, 100)
AddWindowTimer(0, 0, 250)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Timer
      If EventTimer() = 0
        Value = (Value + 5) % 100
        SetGadgetState(1, Value)
      EndIf  
    Case #PB_Event_Gadget
      If EventGadget() = 0
        Debug "buttonpressed"
      EndIf
  EndSelect
Until appQuit
The code only needs to check for the occurrence of three events; all others are moot and require no scrutiny whatsoever.

Your CheckEvent() procedure is totally unnecessary, and renders redundancy in the event loop. :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
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Multiple window problem

Post by collectordave »

collectordave wrote:
Logic to me dictates that i should not do anything I do not have to.
TI-994A wrote
Sound logic; try following it:
Ok. I will try to follow some logic.

This topic is "Multiple Window problem".

The first post demonstrates that problem.

Lots of forum members attempted to look at the problem sometimes a little illogically until
fred Wrote
You should always check for a valid PB event, and ignore all other as they are generated by the OS
and a little light started to shine. It became apparent that EventWindow() could return erronous results until a valid PB event had happened.

of course the forum carried on a little until said posted a solution which actually worked and demonstrated what fred had said.

Checking microsoft you find a little advice. Each window should have it's own event handling procedure and in multiple windows applications it is the responsibility of the applications main message loop to route events to the correct window. Which also makes sense logicaly as why attempt to process events from other windows in the main window event loop?

So useing logic it is best when programming windows to follow microsofts advice.

To do this the EventWindow() procedure needs to work reliably, which can only be guaranteed after a valid pb event.
TI-994A wrote
Assume you have a window with a button and a timer; how do you propose handling each of those events?
After this I posted a working example showing how to process the timer event and a button with the EventWindow() function working correctly.

the reply to this was
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Timer
If EventTimer() = 0
Value = (Value + 5) % 100
SetGadgetState(1, Value)
EndIf
Case #PB_Event_Gadget
If EventGadget() = 0
Debug "buttonpressed"
EndIf
EndSelect
Until appQuit

The code only needs to check for the occurrence of three events; all others are moot and require no scrutiny whatsoever.
Which appears to be a little illogical in this topic of multiple window problem especially after all the posts here have shown that there is an undocumented feature of EventWindow(). To achieve what you are saying there the programme posted simply processes only the events needed. The checkevent() procedure is not processing any events at all just checking that the event that occurred was a valid PB event.
Repeat

event = WaitWindowEvent()

If CheckEvent(event) = #True
If Event = #PB_Event_Timer And EventTimer() = 123
Value = (Value + 5) % 100
SetGadgetState(0, Value)
EndIf

Select EventGadget()
Case Button_0
Debug "buttonpressed"

EndSelect
EndIf
Until event = #PB_Event_CloseWindow
Just about the same except still showing the workaround of the undocumented feature of EventWindow() which keeps us on topic showing the resolution of the Multiple window problem.

Logic then leads me to ask why have you posted here again.

I can imagine a few scenarios.

1. You do not understand the problem.
2. You do not fully understand the processing of windows events
3. You have a problem with logical thinking so cannot accept EventWindow() has an undocumented feature.
4. You are deliberatly attempting to draw the forum users offtopic and attempting to prove what is stated here is incorrect.

I cannot believe the fourth scenario. So I do recommend Programming 101.If it is the third then I am afraid I cannot help.
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: Multiple window problem

Post by TI-994A »

collectordave wrote:1. You do not understand the problem.
2. You do not fully understand the processing of windows events
3. You have a problem with logical thinking so cannot accept EventWindow() has an undocumented feature.
4. You are deliberatly attempting to draw the forum users offtopic and attempting to prove what is stated here is incorrect.
1 and 2 for you! And except the undocumented feature part, 3 too!

Buggy understanding :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: Multiple window problem

Post by collectordave »

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: 4257
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Multiple window problem

Post by Demivec »

@collectordave: It's funny to see how things change. In those treads TI-994A was confused and advocating the same things as you initially and now one year later he says it is obviously wrong to do the things that way. If an experienced user (just ask him :mrgreen: ) can make those kinds of mistakes it is not surprising that newer users do.

It just shows you that sometimes the right way only becomes obvious after making a few wrong turns, hindsight is 20/20. That is another good reason for your request to make some clarification about these things in the help file.
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Multiple window problem

Post by TI-994A »

Demivec wrote:In those treads TI-994A was confused and advocating the same things as you initially and now one year later he says it is obviously wrong to do the things that way.
Funny how I can't seem to find such an advocacy in any of those threads. You've clearly caught a bad case of failure-to-readatitis from collectordave. :wink:
Demivec wrote:If an experienced user (just ask him :mrgreen: ) can make those kinds of mistakes it is not surprising that newer users do.
Aw, shucks! Lil' ol' me? :lol:

Experience boils down to learning; not ignorance.
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: Multiple window problem

Post by collectordave »

All insults aside this whole thing can be simplified to adding just two letters to the manual. Simply put PB in front of event in the manual and help file in the description of the EventWindow() function. Not a large or complicated request.

I can also see that when writing trivial programmes, as most novices do, it is not a bother most of these are just single window or two or three. Only when programmes grow does it become a concern.

I wonder how many novice programmers have been put off taking PB any further when a simple request such as this results in a thread like this one.
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: Multiple window problem

Post by TI-994A »

collectordave wrote:...this whole thing can be simplified to adding just two letters to the manual. Simply put PB in front of event in the manual and help file in the description of the EventWindow() function. Not a large or complicated request.
Your submission of this as a documentation bug was rejected simply because it's not a bug. Persevere, and try the Feature Requests and Wishlists forum.

No point whining about it here. You're even getting Demivec all sloppy and confused. :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
Post Reply