title: Implement message loop to catch all process messages
body: <p>I'm trying to implement a message loop in a control that I can use to peek at all messages in the current process, look for a specific message, and fire an event when a certain message is detected.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>    public void MessageHandler()
      {
          MSG msg;
  
          while (GetMessage(out msg, IntPtr.Zero, 0, 0) &gt; 0)
          {
              if (msg.message == 272)
              {
                  // Fire event here
              }
              else
              {
                  TranslateMessage(ref msg);
                  DispatchMessage(ref msg);
              }
          }
      }
  
      [DllImport("user32.dll")]
      static extern sbyte GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
      [DllImport("user32.dll")]
      static extern bool TranslateMessage([In] ref MSG lpMsg);
      [DllImport("user32.dll")]
      static extern IntPtr DispatchMessage([In] ref MSG lpmsg);
  </code></pre>
  
  <p>This loop is currently being run asynchronously. The issue I'm having is it doesn't seem that I am receiving any messages. The loop exits on the GetMessage() call.</p>
  
  <p>I attempted to run the loop while(true) and continue if the return value from GetMessage() &lt;= 0, but that seemed to produce the same result. </p>
  
  <p>Any input would be greatly appreciated. </p>