closewindow

Just starting out? Need help? Post your questions and find answers here.
mestnyi
Addict
Addict
Posts: 1103
Joined: Mon Nov 25, 2013 6:41 am

closewindow

Post by mestnyi »

Is this how it should be too?

Code: Select all



CompilerIf #PB_Compiler_IsMainFile
   EnableExplicit
   
   Procedure CallBack( )
      Select Event( )
         Case #PB_Event_CloseWindow
            Debug "close - event "+ GetWindowTitle( EventWindow( ) )
            
            CloseWindow( EventWindow( ) )
            
      EndSelect
   EndProcedure
   
   ;\\
   OpenWindow(0, 0, 0, 300, 200, "window_0", #PB_Window_SystemMenu |
                                             #PB_Window_SizeGadget |
                                             #PB_Window_MinimizeGadget |
                                             #PB_Window_MaximizeGadget )
   
   ;\\
   OpenWindow(1, 200, 100, 300, 200, "window_1", #PB_Window_SystemMenu |
                                                 #PB_Window_SizeGadget |
                                                 #PB_Window_MinimizeGadget |
                                                 #PB_Window_MaximizeGadget )
   
   ;\\
   OpenWindow(2, 400, 200, 300, 200, "window_2", #PB_Window_SystemMenu |
                                                 #PB_Window_SizeGadget |
                                                 #PB_Window_MinimizeGadget |
                                                 #PB_Window_MaximizeGadget )
   
   BindEvent( #PB_Event_CloseWindow, @CallBack( ) )
   Define event
   Repeat 
      event = WaitWindowEvent( )
      
      If event = #PB_Event_CloseWindow
        Debug "push close button" 
      EndIf
      
   Until event = #PB_Event_CloseWindow
CompilerEndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4996
Joined: Sun Apr 12, 2009 6:27 am

Re: closewindow

Post by RASHAD »

Maybe :wink:
Check for memory leak

Code: Select all



CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
  
  Procedure CallBack( )
    Select Event( )
      Case #PB_Event_CloseWindow
        Debug "close - event "+ GetWindowTitle( EventWindow( ) )
        If IsWindow(EventWindow( ))
          CloseWindow( EventWindow( ) )
        EndIf        
    EndSelect
  EndProcedure
  
  Define flag,event,Quit
  flag = #PB_Window_SystemMenu |#PB_Window_SizeGadget |#PB_Window_MinimizeGadget |#PB_Window_MaximizeGadget
  OpenWindow(0, 0, 0, 300, 200, "window_0",flag )
  UseGadgetList(WindowID(0))
  ButtonGadget(0,0,0,80,20,"test0")
  
  ;\\
  OpenWindow(1, 200, 100, 300, 200, "window_1", flag )
  UseGadgetList(WindowID(1))
  ButtonGadget(1,0,0,80,20,"test1")
  
  ;\\
  OpenWindow(2, 400, 200, 300, 200, "window_2", flag )
  UseGadgetList(WindowID(2))
  ButtonGadget(2,0,0,80,20,"test2")
  
  BindEvent( #PB_Event_CloseWindow, @CallBack( ) )
  Repeat
    If IsWindow(0) Or IsWindow(1) Or IsWindow(2)
      event = WaitWindowEvent( )
    Else
      Quit = 1
    EndIf
    
    If event = #PB_Event_CloseWindow
      Debug "push close button" 
    EndIf
    
    If event = #PB_Event_Gadget
      Debug EventGadget() 
    EndIf
    
  Until Quit = 1
  
CompilerEndIf
Egypt my love
mestnyi
Addict
Addict
Posts: 1103
Joined: Mon Nov 25, 2013 6:41 am

Re: closewindow

Post by mestnyi »

First, I think it's an overhead to check three procedures in a loop. :)

Code: Select all

If IsWindow(0) Or IsWindow(1) Or IsWindow(2)
Secondly, why should the event from “waitwindowevent()” disappear?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4996
Joined: Sun Apr 12, 2009 6:27 am

Re: closewindow

Post by RASHAD »

OK suit yourself :)
Egypt my love
mestnyi
Addict
Addict
Posts: 1103
Joined: Mon Nov 25, 2013 6:41 am

Re: closewindow

Post by mestnyi »

RASHAD wrote: Sat Dec 02, 2023 7:03 am OK suit yourself :)
:D
mestnyi wrote: Sat Dec 02, 2023 6:58 am Secondly, why should the event from “waitwindowevent()” disappear?
what do you say to this?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4996
Joined: Sun Apr 12, 2009 6:27 am

Re: closewindow

Post by RASHAD »

If you don't have a running window so what is WaitWindowEvent() for
Why don't you create Main window and Child windows so you need only one loop for all windows you have
You can close any child window at any time
But closing the main window will end the applicatin
Egypt my love
mestnyi
Addict
Addict
Posts: 1103
Joined: Mon Nov 25, 2013 6:41 am

Re: closewindow

Post by mestnyi »

I agree with you when it comes to new events, but why should the event be interrupted before reaching the end of the loop?
that's what I mean

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
   EnableExplicit
   
   Procedure CallBack( )
      Select Event( )
         Case #PB_Event_CloseWindow
           Debug EventWindow( )
           
           If IsWindow(EventWindow( ))
             Debug "close - event "+ GetWindowTitle( EventWindow( ) )
             
             CloseWindow( EventWindow( ) )
             
             PostEvent( #PB_Event_CloseWindow, 0 -1 )
            ;  PostEvent( #PB_Event_CloseWindow, -1, -1 )
           EndIf
       EndSelect
   EndProcedure
   
   ;\\
   OpenWindow(1, 0, 0, 300, 200, "window_1", #PB_Window_SystemMenu |
                                             #PB_Window_SizeGadget |
                                             #PB_Window_MinimizeGadget |
                                             #PB_Window_MaximizeGadget )
   
   ;\\
   OpenWindow(2, 200, 100, 300, 200, "window_2", #PB_Window_SystemMenu |
                                                 #PB_Window_SizeGadget |
                                                 #PB_Window_MinimizeGadget |
                                                 #PB_Window_MaximizeGadget )
   
   ;\\
   OpenWindow(3, 400, 200, 300, 200, "window_3", #PB_Window_SystemMenu |
                                                 #PB_Window_SizeGadget |
                                                 #PB_Window_MinimizeGadget |
                                                 #PB_Window_MaximizeGadget )
   
   BindEvent( #PB_Event_CloseWindow, @CallBack( ) )
   Define event
   Repeat 
      event = WaitWindowEvent( )
      
      If event = #PB_Event_CloseWindow
        Debug "push close button" 
      EndIf
      
   Until event = #PB_Event_CloseWindow
CompilerEndIf
User avatar
mk-soft
Always Here
Always Here
Posts: 6329
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: closewindow

Post by mk-soft »

There must always be a window for the event loop.

Update
- You may find it helpful to create a Hidden Main window.

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
  
  Global exit_application
  
  Procedure CallBack( )
    Select Event( )
      Case #PB_Event_CloseWindow
        Select EventWindow( )
          Case 0
            Debug "Close 0"
            CloseWindow(0)
            exit_application = #True
          Case 1
            Debug "Close 1"
            CloseWindow(1)
          Case 2
            Debug "Close 2"
            CloseWindow(2)
        EndSelect
        
    EndSelect
  EndProcedure
  
  ;\\
  Define DoEventWindow
  DoEventWindow = OpenWindow(#PB_Any, 0, 0, 0, 0, "DoEventWindow", #PB_Window_Invisible)
  
  ;\\
  OpenWindow(0, 0, 0, 300, 200, "window_0", #PB_Window_SystemMenu |
                                            #PB_Window_SizeGadget |
                                            #PB_Window_MinimizeGadget |
                                            #PB_Window_MaximizeGadget )
  
  ;\\
  OpenWindow(1, 200, 100, 300, 200, "window_1", #PB_Window_SystemMenu |
                                                #PB_Window_SizeGadget |
                                                #PB_Window_MinimizeGadget |
                                                #PB_Window_MaximizeGadget )
  
  ;\\
  OpenWindow(2, 400, 200, 300, 200, "window_2", #PB_Window_SystemMenu |
                                                #PB_Window_SizeGadget |
                                                #PB_Window_MinimizeGadget |
                                                #PB_Window_MaximizeGadget )
  
  BindEvent( #PB_Event_CloseWindow, @CallBack( ) )
  
  Define event
  
  Repeat 
    event = WaitWindowEvent( )
    
    If event = #PB_Event_CloseWindow
      Debug "push close button" 
    EndIf
    
  Until exit_application
  
  ; do any before exit program
  
CompilerEndIf
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