title: How do I determine how to handle messages using IMessageFilter in a Windows Forms control?
body: <p>I want to access touch input as directly as possible to avoid any lag that may be associated with normal event tunneling and bubbling, so I thought I'd try using messages instead of events. With the following code I can intercept any message that's sent to my <code>WindowsFormsHost</code>:</p>
  
  <pre><code>class FlashFormHost : WindowsFormsHost, IMessageFilter
  {
      public FlashFormHost()
      {
          Application.AddMessageFilter(this);
      }
      public bool PreFilterMessage(ref Message m)
      {
  
          switch (m.Msg)
          {
              // These four messages should be ignored because they're on every frame.
              case 49783:
              case 275:
              case 512:
              case 581:
                  break;
              default:
                  MainWindow.Print(m.Msg + ": " + m.LParam + ", " + m.WParam);
                  break;
          }
          return false;
      }
  }
  </code></pre>
  
  <p>I'm getting three messages every time I touch the control: 585, 582, and 49413. And I'm getting two messages every time I stop touching the control: 583 and 586.</p>
  
  <p>So first of all, how do I know what each message is supposed to mean? Is there a place where I can look up these message numbers?</p>
  
  <p>Also, I'm guessing I should use <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.message.getlparam(v=vs.110).aspx" rel="nofollow noreferrer"><code>Message.GetLParam()</code></a> to get the needed information about the touches: x, y, and ID. But how do I know what type to pass to that method?</p>
  
  <p>I've been trying to look up information about this, but I haven't been able to find anything that solves my issues. There seems to be a table of system messages <a href="https://msdn.microsoft.com/en-us/library/ms644927(v=vs.85).aspx" rel="nofollow noreferrer">here</a> but I don't see it mention touch, and it still doesn't explain what type to pass to <code>GetLParam()</code> in C#.</p>
  
  <p>EDIT: I forgot to mention that I'm using Windows 10. I didn't realize the messages would change between Windows versions.</p>