Could perhaps be tweaked, but one idea is:
Strict Local Window:TGadget = CreateWindow( "Window", 10,10, 400,200) Local sWindow:TGadget = CreateWindow( "sWindow", 10,300, 400,200) Repeat PollEvent If EventID() = EVENT_WINDOWCLOSE Then If EventSource() = Window Then FreeGadget Window Window = Null EndIf If EventSource() = sWindow Then FreeGadget sWindow sWindow = Null EndIf If (Window=Null) And (sWindow=Null) Then End EndIf Forever