When I run the program and close the window, the program still runs in background mode. I don't know why this happens nor how to fix it. Does anybody know what's going on?
AFAIK GetMessage() may return -1 if some error happend, so your loop won't exit.