title: Filtering the Windows message queue
body: <p>I've got a routine that looks something like this, in pseudocode:</p>
  
  <pre><code>while PeekMessage(Message, 0, 0, 0, PM_REMOVE)
    HandleMessageAppropriately(Message)
  </code></pre>
  
  <p>Basically, it goes through and pulls all messages out of the queue and dispatches them.  I can't change this routine.</p>
  
  <p>I've got a scenario in which this routine, if it's being called under certain conditions and there's a message in the queue representing the user having hit <code>ESC</code> at exactly the wrong moment, it can cause the program to crash.  (Gotta love race conditions.)</p>
  
  <p>I can't change the routine above, but I can change the code that calls it.  Is there any way that I can do something immediately before this is run that will say "go through the message queue and remove all keyboard input messages where the user hit ESC, <strong>without affecting the rest of the items in the queue or changing their order</strong>"?</p>