CloseWindow()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

CloseWindow()

Post by mestnyi »

I propose to change the "Close Window" behavior.
Why? Because
1) when you close the window from another window popup notification is not it, that is, software that does not track.
2) at the exit from the cycle again, no popup notification about this, that is that the program is closed.

Code: Select all

Enumeration #PB_Event_FirstCustomValue
  #PB_Event_Quit
EndEnumeration
Procedure CloseWindowAll()
  CloseWindow(#PB_All)
EndProcedure
Procedure CloseWindowEx( Window )
  If Window = #PB_All
    PostEvent( #PB_Event_Quit, EventWindow(), #PB_Ignore ) ; - 1 bug
    BindEvent( #PB_Event_Quit, @CloseWindowAll(), EventWindow())
  Else
    If EventWindow() = Window And Not IsGadget(EventGadget())
      If IsWindow( Window )
        ProcedureReturn CloseWindow( Window )
      EndIf  
    Else
      PostEvent( #PB_Event_CloseWindow, Window, #PB_Ignore ) ; - 1 bug
      ProcedureReturn WindowID(Window)
    EndIf
  EndIf
EndProcedure 
Macro CloseWindow( Window ) 
  CloseWindowEx( Window ) 
EndMacro



X = 100
Global Dim ArrayId.l(4)
Global Event

Procedure CloseAllWindow(*value)
  
 For i = 1 To 4
  
  Delay(1000)
  SetActiveWindow(ArrayId(i))
  CloseWindow(ArrayId(i))
  Debug i
 
 Next
    
EndProcedure

For i = 1 To 4
 ArrayId(i) = OpenWindow(#PB_Any, X, 200, 150, 50, "Window" + Trim(Str(i)))
 X + 300
Next

CreateThread(@CloseAllWindow(), 0)

While Event ! #PB_Event_Quit

   Event = WindowEvent()
   Delay(10)
        
   If Event = #PB_Event_CloseWindow
     If UseGadgetList(0) = WindowID(EventWindow())
       CloseWindow(#PB_All)
       Break
     Else
       CloseWindow(EventWindow())
     EndIf
   EndIf
 Wend
 
Debug "Quit"
MessageRequester("Kcc-MegaBig-Software :-)", "It's ending")
Or so

Code: Select all

Enumeration #PB_Event_FirstCustomValue
  #PB_Event_Quit
EndEnumeration
Procedure CloseWindowEx( Window )
  If Window = #PB_All
     PostEvent( #PB_Event_Quit, EventWindow(), #PB_Ignore ) ; - 1 bug
     CloseWindow( #PB_All ) : OpenWindow( #PB_All, 0,0,0,0, "", #PB_Window_Invisible )
  Else
    If EventWindow() = Window
      If IsWindow( Window )
        ProcedureReturn CloseWindow( Window )
      EndIf  
    Else
      PostEvent( #PB_Event_CloseWindow, Window, #PB_Ignore ) ; - 1 bug
      ProcedureReturn WindowID(Window)
    EndIf
  EndIf
EndProcedure 
Macro CloseWindow( Window ) 
  CloseWindowEx( Window ) 
EndMacro



X = 100
Global Dim ArrayId.l(4)
Global Event

Procedure CloseAllWindow(*value)
  
 For i = 1 To 4
  
  Delay(1000)
  SetActiveWindow(ArrayId(i))
  CloseWindow(ArrayId(i))
  Debug ""+i + " - " + ArrayId(i)
 
 Next
    
EndProcedure

For i = 1 To 4
 ArrayId(i) = OpenWindow(#PB_Any, X, 200, 150, 50, "Window" + Trim(Str(i)))
 X + 300
Next

CreateThread(@CloseAllWindow(), 0)

 Procedure Quit()
   Debug "Quit "+" Window"+EventWindow() ; +CountWindow()
 EndProcedure
 
 BindEvent( #PB_Event_Quit, @Quit())
    
   
While Event <> #PB_Event_Quit
   Event = WindowEvent()
   Delay(10)
        
   If Event = #PB_Event_CloseWindow
     If UseGadgetList(0) = WindowID(EventWindow())
       CloseWindow(#PB_All)
     Else
       CloseWindow(EventWindow())
     EndIf
   EndIf
 Wend
 
Debug "Quit "+EventWindow()
MessageRequester("Kcc-MegaBig-Software :-)", "It's ending") 
End
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: CloseWindow()

Post by Dude »

AFAIK, CloseWindow() is just a wrapper for sending the #WM_CLOSE message (on Windows), so it can't be changed.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CloseWindow()

Post by mestnyi »

sending the #WM_CLOSE message
If so, he is obliged to send event "#PB_Event_CloseWindow"
and with the parameter "#PB_All" required to send event "#PB_Event_Quit"
This is logical. Fred look at this is important. :cry:
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CloseWindow()

Post by mestnyi »

Solution for Windows, I believe closing behavior should be exactly that.
1) If you closed the window we get a message to close the window.
2) If there are no open windows we get the event of withdrawal from the main loop

Here is a demonstration for windows

Code: Select all

EnableExplicit

Enumeration #PB_Event_FirstCustomValue
  #PB_Event_Quit
EndEnumeration

Macro EnableEnumerate
    Import ""
      PB_Object_EnumerateStart( PB_Objects )
      PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
      PB_Object_EnumerateAbort( PB_Objects )
      
      PB_Object_Count( PB_Objects )
      
      PB_Window_Objects.i
    EndImport
  EndMacro : EnableEnumerate

Procedure Callback(WindowID, hMsg, wParam, lParam)
  Static WindowClose
  
  Select hMsg
    Case #WM_CLOSE : WindowClose = #True ;: Debug "#WM_CLOSE = #GDK_DELETE " + EventWindow()
    Case #WM_DESTROY 
      If WindowClose = #True : WindowClose = #False : Else : PostEvent(#PB_Event_CloseWindow, EventWindow(), EventGadget()) : EndIf
      
      If (PB_Object_Count( PB_Window_Objects ) = 1) Or GetProp_( WindowID, "WindowID") = WindowID
        
        Protected Window
        If WindowID
          PB_Object_EnumerateStart( PB_Window_Objects )
          While PB_Object_EnumerateNext( PB_Window_Objects, @Window )
            If IsWindow( Window ) = IsWindow(EventWindow())
              Continue
            Else
              PostEvent(#PB_Event_CloseWindow, Window, EventGadget())
            EndIf
          Wend
          PB_Object_EnumerateAbort( PB_Window_Objects )
        EndIf
        
        OpenWindow(#PB_Any, 0,0,0,0, "", #PB_Window_Invisible )
        PostEvent(#PB_Event_Quit, EventWindow(), EventGadget())
        
        SetWindowCallback( 0 ) ; Bug in purebasic 542
      EndIf
  EndSelect
  
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure 

Procedure WaitCloseWindow( WindowID )
  SetProp_( WindowID, "WindowID", WindowID)
  SetWindowCallback( @Callback() )
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        CloseWindow(EventWindow())
        
      Case #PB_Event_CloseWindow
        Debug "CloseWindow = "+EventWindow()
        
        If IsWindow(EventWindow())
          CloseWindow(EventWindow())
        EndIf
        
      Case #PB_Event_Quit
        Debug ""
        Debug "#PB_Event_Quit EventWindow = "+EventWindow()
        Break
        
    EndSelect
  ForEver
  
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  Define i
  Define X = 100
  
  Procedure CloseWindowHandler()
    Debug "Close event on window #" + EventWindow()
  EndProcedure
  
  For i = 1 To 4
    OpenWindow(i, X, 200, 150, 50, "Window" + Trim(Str(i)),#PB_Window_SystemMenu|#PB_Window_Invisible) :HideWindow(i,0)
    ButtonGadget(i,5,5,80,20,"Quit")
    X + 200
  Next
  
  BindEvent(#PB_Event_CloseWindow, @CloseWindowHandler())
  
  WaitCloseWindow( UseGadgetList(0) )
  
  Debug "Quit"
  
CompilerEndIf

Add this behavior Fred.
Last edited by mestnyi on Sun Apr 03, 2016 9:02 am, edited 4 times in total.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CloseWindow()

Post by mestnyi »

Here is a demonstration for linux

Code: Select all

EnableExplicit

Macro EnableEnumerate
    ImportC ""
      PB_Object_EnumerateStart( PB_Objects )
      PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
      PB_Object_EnumerateAbort( PB_Objects )
      
      PB_Object_Count( PB_Objects )
      
      PB_Window_Objects.i
    EndImport
  EndMacro : EnableEnumerate


Enumeration #PB_Event_FirstCustomValue
   #PB_Event_Quit
EndEnumeration
  
ProcedureC Callback( *Event.GdkEventAny, *WindowID )
  Static WindowClose, WindowID
  Protected *Widget.GtkWidget = *Event\window 
  
  If *Widget\name ; 32 15 16
    CompilerIf #PB_Compiler_Version =< 531
      If *Event\type = #GDK_NOTHING
        Debug PeekS( gtk_widget_get_name_( *Widget\name ), -1, #PB_UTF8 )
        WindowID = *Widget\name
      EndIf
    CompilerElse
      If *Event\type = #GDK_ENTER_NOTIFY
        Debug PeekS( gtk_widget_get_name_( *Event\window  ), -1, #PB_UTF8 )
        WindowID = *Widget\name
      EndIf
    CompilerEndIf
  EndIf
  
  Select *Event\type
    ;Case #GDK_NOTHING : WindowID = *Widget\name
    Case #GDK_DELETE : WindowClose = #True 
    Case #GDK_UNMAP 
      If WindowClose = #True : WindowClose = #False : Else : PostEvent(#PB_Event_CloseWindow, EventWindow(), EventGadget()) : EndIf
      
      Debug WindowID
      Debug *WindowID
        
      If (PB_Object_Count( PB_Window_Objects ) = 0) Or (WindowID = *WindowID)
        
        Protected Window
        If PB_Window_Objects
          PB_Object_EnumerateStart( PB_Window_Objects )
          While PB_Object_EnumerateNext( PB_Window_Objects, @Window )
            If IsWindow( Window ) = IsWindow(EventWindow())
              Continue
            Else
              PostEvent(#PB_Event_CloseWindow, Window, EventGadget())
            EndIf
          Wend
          PB_Object_EnumerateAbort( PB_Window_Objects )
        EndIf
        
        OpenWindow(#PB_Any, 0,0,0,0, "", #PB_Window_Invisible )
        PostEvent(#PB_Event_Quit, EventWindow(), EventGadget())
        
        gdk_event_handler_set_(0, 0, 0)
      EndIf
      ProcedureReturn
    EndSelect
  
  gtk_main_do_event_( *Event )
EndProcedure 

Procedure WaitCloseWindow( WindowID )
  gdk_event_handler_set_( @Callback(), WindowID, 0 )
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        CloseWindow(EventWindow())
        
      Case #PB_Event_CloseWindow
        Debug "CloseWindow = "+EventWindow()
        
        If IsWindow(EventWindow())
          CloseWindow(EventWindow())
        EndIf
        
      Case #PB_Event_Quit
        Debug ""
        Debug "#PB_Event_Quit EventWindow = "+EventWindow()
        Break
        
    EndSelect
  ForEver
  
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  Define i
  Define X = 100
  
  Procedure CloseWindowHandler()
    Debug "Close event on window #" + EventWindow()
  EndProcedure
  
  For i = 1 To 4
    OpenWindow(i, X, 200, 150, 50, "Window" + Trim(Str(i)),#PB_Window_MaximizeGadget|#PB_Window_Invisible) :HideWindow(i,0)
    ButtonGadget(i,5,5,80,20,"Quit")
    X + 200
  Next
  
  BindEvent(#PB_Event_CloseWindow, @CloseWindowHandler())
  
  WaitCloseWindow( UseGadgetList(0) )
  
  Debug "Quit"
  
CompilerEndIf
Add this behavior Fred.
Last edited by mestnyi on Sun Apr 03, 2016 10:32 am, edited 2 times in total.
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: CloseWindow()

Post by Fred »

#PB_Event_CloseWindow is sent when the user clicks on the close button, not when the window is closed. It won't be changed, and to be honest I don't understand anything in your request.
User avatar
mhs
Enthusiast
Enthusiast
Posts: 101
Joined: Thu Jul 02, 2015 4:53 pm
Location: Germany
Contact:

Re: CloseWindow()

Post by mhs »

mestnyi do you mean such a behaviour?

Code: Select all

EnableExplicit

Global.i OpenWindows

Procedure Close(Window)

  Debug "Close Window " + Str(Window)
  
  CloseWindow(Window)
  OpenWindows - 1

EndProcedure

; ---------------

Define.i i, X, Event

For i = 1 To 4
  OpenWindow(i, X, 200, 150, 50, "Window" + Trim(Str(i)),#PB_Window_SystemMenu|#PB_Window_Invisible) :HideWindow(i,0)
  ButtonGadget(i,5,5,80,20,"Quit")
  X + 200
  OpenWindows + 1
Next

Repeat

  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Gadget      : Close(EventWindow())
    Case #PB_Event_CloseWindow : Close(EventWindow())
  EndSelect

Until OpenWindows = 0

Debug "Quit"
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CloseWindow()

Post by mestnyi »

#PB_Event_CloseWindow is sent when the user clicks on the close button, not when the window is closed
If so, where is the window closing event?
And why not use as I propose, and what's wrong with that?
I don't understand anything in your request.
Give the event when there is an open window, not a compiler warning that should be open one window for WaitWindowEvent().
Give the event when the window is closed.
And finally if you hang loop BindEvent () to remove the event from WaitWindowEvent () So far, I have not posted again within BindEvent ().
I hope you got what I meant
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: CloseWindow()

Post by nco2k »

mestnyi wrote:
#PB_Event_CloseWindow is sent when the user clicks on the close button, not when the window is closed
If so, where is the window closing event?
the event is sent when the user is trying to close the window, by pressing the close button, clicking close on the menu, or by pressing alt+f4. CloseWindow() is a function that closes the window immediately. it doesnt ask anything (which is the correct way) and is just a simple wrapper to DestroyWindow_() + some internal cleanup stuff. i honestly dont know what your problem actually is.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CloseWindow()

Post by mestnyi »

mhs
mestnyi do you mean such a behaviour?

Code: Select all

DeclareModule demo
  Declare Open(Window)
EndDeclareModule

Module demo
  Procedure close()
    
    Debug "close demo module"+EventWindow()
  EndProcedure
  
  Procedure closeall()
    
    Debug "closeall demo module"+EventWindow()
  EndProcedure
  
  Procedure Open(Window)
    OpenWindow(Window, 0, 0, 150, 50, "demo",#PB_Window_SystemMenu)
    ButtonGadget(-1,5,5,80,20,"close")
    BindEvent(#PB_Event_CloseWindow, @close(), Window)
    BindEvent(#PB_Event_CloseWindow, @closeall())
  EndProcedure
EndModule

demo::Open(0)

;

EnableExplicit

Global.i OpenWindows

Procedure Close(Window)

  Debug "Close Window " + Str(Window)
  
  CloseWindow(Window)
  OpenWindows - 1

EndProcedure

; ---------------

Define.i i, X, Event


For i = 1 To 4
  OpenWindow(i, X, 200, 150, 50, "Window" + Trim(Str(i)),#PB_Window_SystemMenu|#PB_Window_Invisible) :HideWindow(i,0)
  ButtonGadget(i,5,5,80,20,"Quit")
  X + 200
  OpenWindows + 1
Next

Repeat

  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Gadget      : Close(EventWindow())
    Case #PB_Event_CloseWindow : Close(EventWindow())
  EndSelect

Until OpenWindows = 0

Debug "Quit"
Now, what I propose is an example of how it should be Fred

Code: Select all

DeclareModule demo
  Declare Open(Window)
EndDeclareModule

Module demo
  Procedure close()
    
    Debug "close demo module"+EventWindow()
  EndProcedure
  
  Procedure closeall()
    
    Debug "closeall demo module"+EventWindow()
  EndProcedure
  
  Procedure Open(Window)
    OpenWindow(Window, 0, 0, 150, 50, "demo",#PB_Window_SystemMenu)
    ButtonGadget(-1,5,5,80,20,"close")
    BindEvent(#PB_Event_CloseWindow, @close(), Window)
    BindEvent(#PB_Event_CloseWindow, @closeall())
  EndProcedure
EndModule

demo::Open(0)



EnableExplicit

Enumeration #PB_Event_FirstCustomValue
  #PB_Event_Quit
EndEnumeration

Macro EnableEnumerate
    Import ""
      PB_Object_EnumerateStart( PB_Objects )
      PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
      PB_Object_EnumerateAbort( PB_Objects )
      
      PB_Object_Count( PB_Objects )
      
      PB_Window_Objects.i
    EndImport
  EndMacro : EnableEnumerate

Procedure Callback(WindowID, hMsg, wParam, lParam)
  Static WindowClose
  
  Select hMsg
    Case #WM_CLOSE : WindowClose = #True ;: Debug "#WM_CLOSE = #GDK_DELETE " + EventWindow()
    Case #WM_DESTROY 
      If WindowClose = #True : WindowClose = #False : Else : PostEvent(#PB_Event_CloseWindow, EventWindow(), EventGadget()) : EndIf
      
      If (PB_Object_Count( PB_Window_Objects ) = 1) Or GetProp_( WindowID, "WindowID") = WindowID
        
        Protected Window
        If WindowID
          PB_Object_EnumerateStart( PB_Window_Objects )
          While PB_Object_EnumerateNext( PB_Window_Objects, @Window )
            If IsWindow( Window ) = IsWindow(EventWindow())
              Continue
            Else
              PostEvent(#PB_Event_CloseWindow, Window, EventGadget())
            EndIf
          Wend
          PB_Object_EnumerateAbort( PB_Window_Objects )
        EndIf
        
        OpenWindow(#PB_Any, 0,0,0,0, "", #PB_Window_Invisible )
        PostEvent(#PB_Event_Quit, EventWindow(), EventGadget())
        
        SetWindowCallback( 0 ) ; Bug in purebasic 542
      EndIf
  EndSelect
  
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure 

Procedure WaitCloseWindow( WindowID )
  SetProp_( WindowID, "WindowID", WindowID)
  SetWindowCallback( @Callback() )
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        CloseWindow(EventWindow())
        
      Case #PB_Event_CloseWindow
        Debug "CloseWindow = "+EventWindow()
        
        If IsWindow(EventWindow())
          CloseWindow(EventWindow())
        EndIf
        
      Case #PB_Event_Quit
        Debug ""
        Debug "#PB_Event_Quit EventWindow = "+EventWindow()
        Break
        
    EndSelect
  ForEver
  
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  Define i
  Define X = 100
  
  Procedure CloseWindowHandler()
    Debug "Close event on window #" + EventWindow()
  EndProcedure
  
  For i = 1 To 4
    OpenWindow(i, X, 200, 150, 50, "Window" + Trim(Str(i)),#PB_Window_SystemMenu|#PB_Window_Invisible) :HideWindow(i,0)
    ButtonGadget(i,5,5,80,20,"Quit")
    X + 200
  Next
  
  BindEvent(#PB_Event_CloseWindow, @CloseWindowHandler())
  
  WaitCloseWindow( UseGadgetList(0) )
  
  Debug "Quit"
  
CompilerEndIf

mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CloseWindow()

Post by mestnyi »

#PB_Event_CloseWindow is sent when the user clicks on the close button, not when the window is closed. It won't be changed, and to be honest I don't understand anything in your request.
If this is so then how do I know if my window has been closed ???
And why do analogous events such as maximization and minimization behave differently, notifying about their state that is sending the event?
That's what I was asking to get an event when my window wants to close this behavior I think is right.

Code: Select all

If OpenWindow(0, 100, 200, 195, 260, "Window_0", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
  OpenWindow(10, 100, 200, 195, 260, "Window_10", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
  StickyWindow(10,1)
  
  ButtonGadget(1, 10, 10, 175, 20, "close")
  ButtonGadget(2, 10, 35, 175, 20, "maximize")
  ButtonGadget(3, 10, 60, 175, 20, "minimize")
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_CloseWindow 
      Debug "close"
      If EventWindow() = 10 : Quit = 1 : EndIf
    ElseIf Event = #PB_Event_MaximizeWindow
      Debug "maximize"
    ElseIf Event = #PB_Event_MinimizeWindow
      Debug "minimize"
    ElseIf Event = #PB_Event_Gadget
      Select EventGadget()
        Case 1 : CloseWindow(0) ; How should I know that my window has been closed??????????????????
        Case 2 : SetWindowState(0, #PB_Window_Maximize) 
        Case 3 : SetWindowState(0, #PB_Window_Minimize)
      EndSelect
    EndIf
    
  Until Quit = 1
EndIf

End   
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: CloseWindow()

Post by nco2k »

why bumping an old thread?
mestnyi wrote:If this is so then how do I know if my window has been closed ???
IsWindow()
mestnyi wrote:And why do analogous events such as maximization and minimization behave differently
because its a design choice, and a very common one. #PB_Event_CloseWindow gets sent before closing the window. it notifies you that the user is requesting to close the window. you then have to manually either allow or deny that request, by using CloseWindow() or doing nothing. #PB_Event_Minimize/MaximizeWindow gets sent after minimizing/maximizing the window. it notifies you that the window state has changed. you dont have to do anything, because the state change already took place. if you want to override this behavior, feel free to use a callback. there are plenty of examples on the forum.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: CloseWindow()

Post by Dude »

mestnyi wrote:If this is so then how do I know if my window has been closed ???
Only you can close it, so you should already know. :wink:
mestnyi wrote:why do analogous events such as maximization and minimization behave differently, notifying about their state that is sending the event?
They don't. You're still maxing and minning them yourself, just like when you close a window yourself. Your own code even shows you doing it. :)
mestnyi wrote:Case 1 : CloseWindow(0) ; How should I know that my window has been closed??????????????????
I think you're looking for something like this:

Code: Select all

Case 1 : If IsWindow(0) : CloseWindow(0) : EndIf
But you shouldn't need IsWindow() because you're meant to keep track of what you're doing with your windows.

I think this whole thread is just a coding logic issue, rather than a valid feature request (sorry!).
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: CloseWindow()

Post by mestnyi »

Well, it's difficult to get to you.
If I closed the window myself, then there would not be any problems. And I'm talking about when I write a module, for example, and inside the module, I need to know that my window is closed, so how do I find out? Of course I can give them a procedure so that they call it when they want to close my module. But I wanted that I knew that my window was closed.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: CloseWindow()

Post by mk-soft »

This one can be solved with BindEvent()

before the function WaitWindowEvent() is executed, all callbacks are called.

Code: Select all

;-TOP

DeclareModule MyDialog
  
  Declare Open(ParentWindow)
  
EndDeclareModule

Module MyDialog
  
  Global win
  
  Procedure CloseDialog()
    ; Unbind
    UnbindEvent(#PB_Event_CloseWindow, @CloseDialog(), win)
    UnbindEvent(#PB_Event_CloseWindow, @CloseDialog(), ParentWindow)
    Debug "ToDo Close Diaglog ..."
    If EventWindow() = win
      Debug "Close from dialog"
    Else
      Debug "Close from main"
    EndIf
    CloseWindow(win)
    Debug "Ready."
  EndProcedure
  
  Procedure Open(ParentWindow)
    win = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 300, 200, "MyDialog", #PB_Window_Tool | #PB_Window_SystemMenu, ParentWindow)
    ; Bind
    BindEvent(#PB_Event_CloseWindow, @CloseDialog(), win)
    BindEvent(#PB_Event_CloseWindow, @CloseDialog(), ParentWindow)
    
    ; Code
  EndProcedure
  
EndModule

; Help window for dispatch events - We needed allway one window for do events
Global MyHideWindow = OpenWindow(#PB_Any,0,0,0,0, "DoEvents", #PB_Window_Invisible | #PB_Window_NoGadgets); | #PB_Window_NoActivate)

Global ExitApplication

Procedure CloseMain()
  Debug "ToDo Close MainWindow ..."
  Debug "Ready."
  CloseWindow(0)
  ExitApplication = #True
EndProcedure


Procedure Main()
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 400, 300, "Main", #PB_Window_SystemMenu)
    BindEvent(#PB_Event_CloseWindow, @CloseMain(), 0)
    MyDialog::Open(0)
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          If EventWindow() = 0
            ;CloseWindow(0)
            Break
          EndIf
      EndSelect
      
    Until ExitApplication
    
  EndIf
  
EndProcedure : Main()

End
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply