It is currently Thu Feb 20, 2020 7:13 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 49 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Multiple window problem
PostPosted: Mon Oct 19, 2015 2:08 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1064
Location: Portugal
Just trying to open a second window from a main window but thought I noticed something strange so programmed the following to test.

I see this as very strange or a bug. What am I doing wrong?

Code:
IncludeFile "Window2.pb"

Global MainWindow.l,Wnd2.l

MainWindow = OpenWindow(#PB_Any, 0, 0, 600, 220, "", #PB_Window_SystemMenu)
frmMain = OpenWindow(#PB_Any, 0, 0, 600, 220, "", #PB_Window_SystemMenu)
CreateMenu(100, WindowID(frmMain))
  MenuTitle("File")
  MenuItem(101, "Open")

Repeat
 
  event = WaitWindowEvent()
 
  If EventWindow() = Wnd2;Select window.

      Window2::Event_Handler(event)
      Debug EventWindow()
     
    EndIf ;EventWindow()
     
 ;Not the second window so must be the main window
 Select event
     
   Case #PB_Event_Menu
     
     Select EventMenu()
             
       ;Only one menu item
      Case 101
        ;Show the 2nd window
        Debug "Open 2nd"
        Wnd2 = Window2::OpenWnd2()
       
     EndSelect ;Eventmenu
       
   Case   #PB_Event_CloseWindow
         
     End
         
 EndSelect ;Event

ForEver


The above is the main window

Code:

DeclareModule Window2
 
  Global ThisWindow.l
  Global Ok.i = 0
 
  Declare.l OpenWnd2()
  Declare Event_Handler(event)
 
EndDeclareModule

Module Window2

Global btnOk, btnCancel

Procedure.l OpenWnd2()
 
  ThisWindow = OpenWindow(#PB_Any, x, y, 280, 180, "Test Window", #PB_Window_SystemMenu)
  btnOk = ButtonGadget(#PB_Any, 130, 140, 60, 30, "Ok")
  btnCancel = ButtonGadget(#PB_Any, 210, 140, 60, 30, "Cancel")
 
  ProcedureReturn ThisWindow
 
EndProcedure

Procedure Event_Handler(event)
 
  Select event
     
    Case #PB_Event_CloseWindow
     
      CloseWindow(ThisWindow)

    Case #PB_Event_Gadget
     
      Select EventGadget()
         
        Case   btnOk
         
          Ok = 1
          CloseWindow(ThisWindow)
         
        Case btnCancel
         
          Ok = 0
          CloseWindow(ThisWindow)

      EndSelect
     
  EndSelect
 
EndProcedure

EndModule


That is the include file.

Works fine. Click menu item and second window opens click close and all is ok.
However I noticed that whatever event happens on either window when both are open EventWindow() allways comes back with the second window identifier even with mouse move events on the main window! Moving the two apart has no effect. You can see this from the debug statements I have added.

_________________
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 2:21 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Jun 01, 2012 12:20 am
Posts: 140
Hi,

Not sure about the issue, but I think an "Else" statement in needed in the event loop:

Code:


DeclareModule Window2
 
  Global ThisWindow.l
  Global Ok.i = 0
 
  Declare.l OpenWnd2()
  Declare Event_Handler(event)
 
EndDeclareModule

Module Window2

Global btnOk, btnCancel

Procedure.l OpenWnd2()
 
  ThisWindow = OpenWindow(#PB_Any, x, y, 280, 180, "Test Window", #PB_Window_SystemMenu)
  btnOk = ButtonGadget(#PB_Any, 130, 140, 60, 30, "Ok")
  btnCancel = ButtonGadget(#PB_Any, 210, 140, 60, 30, "Cancel")
 
  ProcedureReturn ThisWindow
 
EndProcedure

Procedure Event_Handler(event)
 
  Select event
     
    Case #PB_Event_CloseWindow
     
      CloseWindow(ThisWindow)

    Case #PB_Event_Gadget
     
      Select EventGadget()
         
        Case   btnOk
         
          Ok = 1
          CloseWindow(ThisWindow)
         
        Case btnCancel
         
          Ok = 0
          CloseWindow(ThisWindow)

      EndSelect
     
  EndSelect
 
EndProcedure

EndModule



Global MainWindow.l,Wnd2.l

MainWindow = OpenWindow(#PB_Any, 0, 0, 600, 220, "", #PB_Window_SystemMenu)
frmMain = OpenWindow(#PB_Any, 0, 0, 600, 220, "", #PB_Window_SystemMenu)
CreateMenu(100, WindowID(frmMain))
  MenuTitle("File")
  MenuItem(101, "Open")

Repeat
 
  event = WaitWindowEvent()
 
  If EventWindow() = Wnd2;Select window.

      Window2::Event_Handler(event)
      Debug EventWindow()
     
     
     
 Else ;   <------ Not the second window so must be the main window
     
 
 Select event
     
   Case #PB_Event_Menu
     
     Select EventMenu()
             
       ;Only one menu item
      Case 101
        ;Show the 2nd window
        Debug "Open 2nd"
        Wnd2 = Window2::OpenWnd2()
       
     EndSelect ;Eventmenu
       
   Case   #PB_Event_CloseWindow
         
     End
         
 EndSelect ;Event
 
    EndIf ;EventWindow()
 
ForEver




Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 2:28 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1064
Location: Portugal
Sorry

tried that but still the same. eventWindow() still saying all events are from the 2nd window.

if you change the code after eventwindow() to this

If EventWindow() = Wnd2;Select window.

Window2::Event_Handler(event)
Debug EventWindow()
Debug wnd2

you can see in the debug window that the same ID is displayed at all times even when you are nowhere near the second window. I expected an event on the mainwindow would raise an event for the mainwindow but seems I am mistaken

_________________
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 2:38 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1064
Location: Portugal
A bit more info

I added the following

If EventWindow() = MainWindow
Debug "Main"
EndIf

right after the waitwindowevent just in case

The debug shows "Main" once when opened but not for mousemoves etc these still goto the 2nd window.

The behaviour stops after closing the 2nd window.

_________________
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 3:00 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4518
Location: Germany
Hi,

forget my post, I made a typo.

Bernd


Last edited by infratec on Mon Oct 19, 2015 3:08 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 3:08 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13894
Location: France
You use frmMain for creation and WindowMain for testing, sounds like a typo error.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 3:18 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4518
Location: Germany
I can not reproduce it:
Code:
DeclareModule Window2
 
  Global ThisWindow.i
  Global Ok.i = 0
 
  Declare.i OpenWnd2()
  Declare Event_Handler(event)
 
EndDeclareModule

Module Window2

  Global btnOk, btnCancel
 
  Procedure.i OpenWnd2()
   
    ThisWindow = OpenWindow(#PB_Any, x, y, 280, 180, "Wnd2", #PB_Window_SystemMenu)
    btnOk = ButtonGadget(#PB_Any, 130, 140, 60, 30, "Ok")
    btnCancel = ButtonGadget(#PB_Any, 210, 140, 60, 30, "Cancel")
   
    ProcedureReturn ThisWindow
   
  EndProcedure
 
  Procedure Event_Handler(event)
   
    Select event
     
      Case #PB_Event_CloseWindow
        CloseWindow(ThisWindow)
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case btnOk
            Ok = 1
            CloseWindow(ThisWindow)
           
          Case btnCancel
            Ok = 0
            CloseWindow(ThisWindow)
           
        EndSelect
       
    EndSelect
   
  EndProcedure
 
EndModule

Global MainWindow.i, Wnd2.i

MainWindow = OpenWindow(#PB_Any, 0, 0, 600, 220, "MainWindow", #PB_Window_SystemMenu)
frmMain = OpenWindow(#PB_Any, 0, 0, 600, 220, "frmMain", #PB_Window_SystemMenu)
CreateMenu(100, WindowID(frmMain))
  MenuTitle("File")
  MenuItem(101, "Open")

Repeat
 
  event = WaitWindowEvent()
 
  Select EventWindow()
    Case Wnd2;Select window.
      Debug "Wnd2"
      Window2::Event_Handler(event)
     
    Case frmMain
      Debug "frmWindow"
      Select event
        Case #PB_Event_Menu
          Select EventMenu()
            Case 101
              ;Show the 2nd window
              Debug "Open 2nd"
              Wnd2 = Window2::OpenWnd2()
           
          EndSelect ;Eventmenu
       
        Case #PB_Event_CloseWindow
          End
         
      EndSelect
     
    Case MainWindow
      Debug "MainWindow"
     
  EndSelect
 
ForEver


Bernd


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 3:27 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1064
Location: Portugal
Hi Bernd

Copied and posted your code above straight in to a new file and the same problem happens.

I am running windows 7 if that has any bearing

_________________
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 3:30 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13894
Location: France
No problem here, and it's a very simple code so I don't think there is any bug here.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 3:35 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4518
Location: Germany
Hi,

you know that you get only mouse events for an active window?


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 4:01 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1064
Location: Portugal
thanks yes

Really optimised the code to

Code:

OpenWindow(1000, 0, 0, 600, 220, "MainWindow", #PB_Window_SystemMenu)
OpenWindow(1001, 300, 300, 280, 180, "Wnd2", #PB_Window_SystemMenu)

Repeat
 
  event = WaitWindowEvent()
 
  Select EventWindow()
     
    Case 1001
      Debug "Wnd2"
     
    Case 1000
      Debug "MainWindow"
     
   EndSelect  ;EventWindow()

Until event = #PB_Event_CloseWindow


So nothing at all should get in the way.

Starts and runs fine. Both windows are created debug window just shows Main Window once. I then clicked on the debug window and Wnd2 turned up.

Going a little further I moved the mouse over the second window and nothing. Moved the mouse over the main window and nothing not quite what I was expecting but good. I then clicked on the main window and hey presto lots and lots of main window events. Just to be sure i moved the mouse to the second window and still lots more main window events. You do have to keep clearing the debug window of course. I then click on the second window (after clearing the debug window again) and hey presto lots of 2nd window events even when moving to the main window with the mouse, clearing as i go.

Next step was to close down PureBasic completely and restart. Same thing happens.

The code cannot get any simpler can it?

_________________
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 5:07 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13894
Location: France
Some events can be fired here and here, you have to test for a specific event (like PB_Event_CloseWindow etc.). Just monitoring if a window gets an event isn't reliable (and doesn't make sens).


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 6:07 pm 
Offline
User
User
User avatar

Joined: Sat Jan 30, 2010 10:10 am
Posts: 62
Location: Laufen, Bavaria, Germany
Hi everyone,
playing around with some values I made the following change on the second example of acreis:

Code:
If EventWindow() = Wnd2 ; Select window.

  Window2::Event_Handler(event)
  ; Debug EventWindow()

  Debug Str(Wnd2) + " - " + str(event) ; modified line

Else ; <------ Not the second window so must be the main window


Now we can see which events are fired; with my system there are many 512 codes fired and acording to the #PB_Event_xxx constants that code is no official event response of PB.
However, if you don't close the opened second window and click on the first window the fired events for the second window are gone. So the events only show up if the second window is active and you hover over any window.

Maybe this helps collectordave to get closer into debugging this behaviour. In my opinion no bug because you have to explicly examine a matching PB-eventcode (#PB_Event_xxx) in your eventloop.

Does this make sense? :D
Bye Harry.

_________________
- Sherlock Holmes - "When you have eliminated the impossible, whatever remains, however improbable, must be the truth."
In my opinion, he must have been a programmer.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Mon Oct 19, 2015 6:31 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1064
Location: Portugal
The point is not the messages that are fired these are handled where required. It is when moveing the mouse over the second window when the main one has the focus fires events for the mainwindow. Vice versa as well.

windows message 512 is the mousemove event. they can all be seen here

http://wiki.winehq.org/List_Of_Windows_Messages

So not the messages. It is eventwindow() reporting the wrong window for the messages. It is this that makes no sense, I expect to get lots of messages for each window when the window is active such as 512 that is not a bother. When i make the main window active by clicking the titlebar then move the mouse pointer to the second window I still get the 512 message assigned to the main window while moveing the mouse over the second window.

Taking it a little further I have uninstalled pureBasic and reinstalled the latest release but the bug is still there.

Next is another computer that has not been used for a while then the mac mini.

_________________
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Multiple window problem
PostPosted: Tue Oct 20, 2015 2:34 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3618
Location: Utah, USA
Here is my version of your code, it should not be run with the debugger.

Code:
OpenWindow(1000, 0, 0, 600, 220, "MainWindow", #PB_Window_SystemMenu)
OpenWindow(1001, 300, 300, 280, 180, "Wnd2", #PB_Window_SystemMenu)
OpenWindow(1002, 600, 300, 250, 500, "Output", #PB_Window_SystemMenu)
ButtonGadget(1, 75, 20, 100, 20, "Clear")
TextGadget(#PB_Any, 0, 0, 250, 20, "Newest events listed first.")
ListViewGadget(0, 0, 40, 250, 480)

Repeat
 
  event = WaitWindowEvent()
 
  Select event
    Case #PB_Event_Gadget
     
      Select EventGadget()
        Case 1 ;button
          ClearGadgetItems(0)
      EndSelect
     
    Case #PB_Event_CloseWindow
      End
    Default
     
      Select EventWindow()
         
        Case 1001
          AddGadgetItem(0, 0, "Wnd2: event " + event)
         
        Case 1000
          AddGadgetItem(0, 0, "MainWindow: event " + event)

        Default
          If EventWindow() <> 1002
            AddGadgetItem(0, 0, "(" + EventWindow() + "): event " + event)
          EndIf
      EndSelect  ;EventWindow()
  EndSelect
 
 
Until event = #PB_Event_CloseWindow


I set things up this way to avoid any complications from the debugger interactions in the code.

It shows similar results by reporting events for the active window even when the mouse is moved over a different window.

_________________
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 49 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye