Window closing events

The events for windows closing and being unable to end the program are
now handled.