how can i connect window's close button with my function.