CloseWindow()

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

CloseWindow()

Post by jak64 »

Good morning,

I wrote :

Case #PB_Event_CloseWindow
IfIsWindow(0)
CloseWindow(0)
ElseIf IsWindow(1)
CloseWindow(1)
EndIf

And it doesn't work.
I would like that by clicking the X of window 0, window 0 is closed
And by clicking on the X of window 1, window 1 is closed but not window 0
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: CloseWindow()

Post by Caronte3D »

You don't do it right

You must use: EventWindow() to know wich window produce the event.

IsWindow is only to know if a window is a window really
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: CloseWindow()

Post by jak64 »

Hello Caronte3D,

thank you, it works great :D
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: CloseWindow()

Post by jacdelad »

Maybe

Code: Select all

;Create Windows

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      CloseWindow(EventWindow())
  EndSelect
ForEver
...but now you don't have an option to stop the program.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: CloseWindow()

Post by jak64 »

Thank you jacdelad
Mesa
Enthusiast
Enthusiast
Posts: 345
Joined: Fri Feb 24, 2012 10:19 am

Re: CloseWindow()

Post by Mesa »

Code: Select all

If OpenWindow(0, 0, 0, 220, 100, "Ex1", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ButtonGadget  (1, 10, 60, 200, 30, "Close all")
	
	OpenWindow(1, 100, 0, 220, 100, "Ex2", #PB_Window_SystemMenu )
	OpenWindow(2, 200, 200, 220, 100, "Ex3", #PB_Window_SystemMenu )
	
	
	Repeat
		Event = WaitWindowEvent()
		Win = EventWindow()
		
		Select Event
			Case #PB_Event_CloseWindow
				
				Select win
					Case 0
						quit=1
						
					Case 1,2
						CloseWindow(Win)
						
				EndSelect
				
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1 
						CloseWindow(0)
						End  
				EndSelect
				
		EndSelect
	Until quit=1
EndIf

M.
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: CloseWindow()

Post by jak64 »

Hello Mesa,

Thank you for this very clear example.
AZJIO
Addict
Addict
Posts: 1318
Joined: Sun May 14, 2017 1:48 am

Re: CloseWindow()

Post by AZJIO »

I use a different selection nesting so that each window's events are enumerated in its own section of code.

Code: Select all

Enumeration
	#Win0
	#Win1
	#Win2
EndEnumeration

#btn = 0


If OpenWindow(#Win0, 0, 0, 220, 100, "Ex1", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ButtonGadget(#btn, 10, 60, 200, 30, "Close all")
	
	OpenWindow(#Win1, 100, 0, 220, 100, "Ex2", #PB_Window_SystemMenu )
	OpenWindow(#Win2, 200, 200, 220, 100, "Ex3", #PB_Window_SystemMenu )
	
	
	Repeat
		WWE = WaitWindowEvent()
		EvWin = EventWindow()
		
		Select EvWin
				
			Case #Win0
				Select WWE
					Case #PB_Event_Gadget
						Select EventGadget()
							Case #btn
; 								CloseWindow(#Win0)
								End  
						EndSelect
					Case #PB_Event_CloseWindow
						End
				EndSelect
				
			Case #Win1
				Select WWE
					Case #PB_Event_CloseWindow
						CloseWindow(#Win1)
				EndSelect
				
			Case #Win2
				Select WWE
					Case #PB_Event_CloseWindow
						CloseWindow(#Win2)
				EndSelect

		EndSelect
	ForEver
EndIf
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: CloseWindow()

Post by jak64 »

Thank You AZJIO
Post Reply