Your code in this thread is identical to your previous post, where you had a problem with the window not closing whenever the X button in the upper right corner is pressed. The thread I’m refering to is this:
Have you tried icculus’ solution to the problem?