The
documentation of PeekMessage says that it only returns false, if no message is available. Take also a look at the example code in this articel.
Make an output of the incoming messages to better understand the incoming messages.
Your code snippet: the outer loop will only get exited with the return, else you get an re-entry per the heading while.