Page 1 of 1

Close parent window

Posted: Wed Aug 02, 2023 7:41 pm
by User_Russian
Why does the close window with ID 1 when the close window with ID 0?

Code: Select all

If OpenWindow(0, 0, 0, 400, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  OpenWindow(1, 200, 200, 200, 200,"",#PB_Window_MinimizeGadget, WindowID(0))
  AddWindowTimer(0, 123, 2500)
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Timer And EventTimer() = 123
      CloseWindow(0)
      Debug IsWindow(0)
      Debug IsWindow(1)
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
EndIf

// Moved from "Bugs - Windows" to "General Discussion" (Kiffi)

Re: Close parent window

Posted: Wed Aug 02, 2023 8:11 pm
by mk-soft
Because Window 1 is a child of Window 0.
When Window 0 is closed, all child objects are also closed.

Re: Close parent window

Posted: Wed Aug 02, 2023 10:22 pm
by User_Russian

Re: Close parent window

Posted: Wed Aug 02, 2023 10:39 pm
by Little John
By definition, a child window is one that is dependent on a parent window and is closed when the parent window closes.
Fred cannot write everything about computer programming in the PB help.

Re: Close parent window

Posted: Thu Aug 03, 2023 10:27 am
by User_Russian
In PB doesn't have a cross-platform method to unbind a window from its parent window.
It is necessary that the window with ID 1 does not close.

Re: Close parent window

Posted: Thu Aug 03, 2023 11:43 am
by AZJIO
put it away

Code: Select all

WindowID(0)

Re: Close parent window

Posted: Thu Aug 03, 2023 12:03 pm
by Little John
User_Russian wrote: Thu Aug 03, 2023 10:27 am In PB doesn't have a cross-platform method to unbind a window from its parent window.
If you want such a method, you can make a feature request for it.
But asking for a change of the current correct behaviour when a parent window closes doesn't make sense. And it's not a bug anyway.

Re: Close parent window

Posted: Thu Aug 03, 2023 5:43 pm
by AZJIO
SetParent_() ?
set the parent window for the child window before closing the main window

Re: Close parent window

Posted: Thu Aug 03, 2023 5:52 pm
by jacdelad
AZJIO wrote: Thu Aug 03, 2023 5:43 pm SetParent_() ?
set the parent window for the child window before closing the main window
...only on Windows.

Re: Close parent window

Posted: Thu Aug 03, 2023 7:05 pm
by mk-soft
Solution:
A little trick to prevent several windows from the same programme from being displayed in the taskbar.

Code: Select all

;-TOP by mk-soft

If OpenWindow(0, -1, -1, 0, 0, "WindowDoEvents", #PB_Window_BorderLess)
  If OpenWindow(1, 0, 0, 400, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered, WindowID(0))
    OpenWindow(2, 200, 200, 200, 200,"",#PB_Window_MinimizeGadget, WindowID(0))
    AddWindowTimer(0, 123, 2500)
    
    Repeat
      Event = WaitWindowEvent()
      
      If Event = #PB_Event_Timer And EventTimer() = 123
        CloseWindow(1)
        RemoveWindowTimer(0, 123)
        Debug IsWindow(1)
        Debug IsWindow(2)
      EndIf    
      
    Until Event = #PB_Event_CloseWindow
  EndIf
EndIf

Re: Close parent window

Posted: Thu Aug 03, 2023 10:27 pm
by User_Russian
AZJIO wrote: Thu Aug 03, 2023 5:43 pm SetParent_() ?
set the parent window for the child window before closing the main window
This does not work.

Code: Select all

If OpenWindow(0, 0, 0, 400, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  OpenWindow(1, 200, 200, 200, 200,"",#PB_Window_MinimizeGadget, WindowID(0))
  AddWindowTimer(0, 123, 2500)
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Timer And EventTimer() = 123
      ;SetParent_(WindowID(1), 0)
      SetParent_(WindowID(1), GetDesktopWindow_())
      CloseWindow(0)
      Debug IsWindow(0)
      Debug IsWindow(1)
    EndIf    
    
  Until Event = #PB_Event_CloseWindow
EndIf