title: Intercepting Window Messages for another Window
body: <p>I'm using CefGlue to make an application with an embedded webkit browser in it, and I need to listen for mousemovements in the browser window. The winforms control doesn't pass down mouse events to the control so I can't listen to them.</p>
  
  <p>However, I found a bug/feature request with a solution in it, but it's beyond me on how to implement it, I'm not familiar with working directly in the WinAPI. The developer says I need to:</p>
  
  <blockquote>
    <p><em>2</em>. OS-specific (windows) - after browser created (CefLifeSpanHandler.OnAfterCreated) get window handle and subclass
    them (window subclassing technique). Actually now we have native
    window with class CefBrowserWindow (returned by
    CefBrowser.GetHost().GetWindowHandle()), then child window
    Chrome_WidgetWin_0, and then Chrome_RenderWidgetHostHWND. For
    intercepting WM_MOUSEMOVE you are interesting in Chrome_WidgetWin_0
    window, which can be easily obtained via CefBrowserWindow. Just play
    with Spy++ to see precisely.</p>
    
    <p><a href="https://bitbucket.org/xilium/xilium.cefglue/issue/4/mouse-events-unaccessible" rel="nofollow">https://bitbucket.org/xilium/xilium.cefglue/issue/4/mouse-events-unaccessible</a></p>
  </blockquote>
  
  <p>I've done some googling, but I'm not sure how to hook into this. I have this function on my form: </p>
  
  <pre><code>    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
      protected override void WndProc(ref Message m) {
          base.WndProc(ref m);
  
          switch (m.Msg) {
              case WM_MOUSEMOVE:
                  Console.WriteLine("Mouse move!");
                  break;
              default:
                  Console.WriteLine(m.ToString());
                  break;
          }
      }
  </code></pre>
  
  <p>But I never see a mouse move when I'm over the control. I suspect I need to be listening on the WndProc of <code>CefBrowser.GetHost().GetWindowHandle()</code> But I'm not sure how to do that.</p>