Oh shoot, I hate it when I do this sort of thing Everything works fine and as expected if I check for WM_COMMAND and WM_CLOSE in the dialog procedure, although for some reason it doesn't work when I check in the message loop. The reason I checked in the message loop was to avoid using yet another global variable, but in this case I can't see how to avoid it Any ideas, or should I just get on with my life and leave the global variable there?