Windows doesn't close windows when a user logs off; that's your call
Commenter Peter Kankowski asks why Windows doesn't send and messages when the user logs off. That's what is for. To tell the program that the Windows session is ending, and that you should get done whatever last things you want to get done before the world comes to an end. Windows doesn't send the message because sending becomes complicated...