title: WM_MOUSEHOVER in a global hook
body: <p>I have implemented custom tooltips for a couple of controls in my application (MFC) but I would like to make it general for all the controls.</p>
  
  <p>Right now I am calling TrackMouseEvent in <code>WM_MOUSEMOVE</code> and then catching <code>WM_MOUSEHOVER</code> (both in the overwritten function WindowProc of the control). But this way I have to duplicate code for every control. So my intention was to set a global hook for mouse events and there ask the control for the message to display in the tooltip.</p>
  
  <p>The problem is that I am not able to catch <code>WM_MOUSEHOVER</code> in a global hook. This is the code:</p>
  
  <pre><code>hMouseHook = SetWindowsHookEx(  WH_MOUSE, 
                                  CallWndMouseProc, 
                                  NULL,
                                  AfxGetThread()-&gt;m_nThreadID);
  hMainHook = SetWindowsHookEx(   WH_CALLWNDPROC, 
                                  CallWndProc, 
                                  NULL,
                                  AfxGetThread()-&gt;m_nThreadID);
  
   LRESULT CALLBACK CallWndMouseProc( int nCode, 
                                      WPARAM wParam, 
                                      LPARAM lParam )
  {
      if(nCode == HC_ACTION) 
      {
          MOUSEHOOKSTRUCT* pwp = (MOUSEHOOKSTRUCT*)lParam;
          TRACE(  _T("message: %x hwnd: %x x: %d y: %d\n"),
                      wParam,
                      pwp-&gt;hwnd,
                      pwp-&gt;pt.x,
                      pwp-&gt;pt.y);
  
          TRACKMOUSEEVENT eventTrack;
  
          eventTrack.cbSize      = sizeof(TRACKMOUSEEVENT);
          eventTrack.dwFlags     = TME_HOVER;
          eventTrack.dwHoverTime = HOVER_DEFAULT;
          eventTrack.hwndTrack   = pwp-&gt;hwnd;
  
          _TrackMouseEvent(&amp;eventTrack);
  
          if(wParam == WM_MOUSEHOVER)
          {
              AfxMessageBox(_T("CallWndMouseProc: WM_MOUSEHOVER"));
          }
      } 
  
      // let the  messages through to the next hook 
      return CallNextHookEx(  hMouseHook, 
                              nCode, 
                              wParam, 
                              lParam); 
  }
  
  LRESULT CALLBACK CallWndProc(   int nCode, 
                                  WPARAM wParam, 
                                  LPARAM lParam )
  {
      if(nCode == HC_ACTION) 
      {
          CWPSTRUCT *pData = (CWPSTRUCT*)lParam;
          if(pData-&gt;message == WM_MOUSEHOVER)
          {
              AfxMessageBox(_T("CallWndProc: WM_MOUSEHOVER"));
          }
      } 
  
      // let the  messages through to the next hook 
      return CallNextHookEx(  hMainHook, 
                              nCode, 
                              wParam, 
                              lParam); 
  }
  </code></pre>
  
  <p>Both hooks are being call for the rest of messages and I am sure <code>WM_MOUSEHOVER</code> is being sent because it's capture in the WindowProc function. For instance this is the WindowProc function for a custom CListBox:</p>
  
  <pre><code>LRESULT CMyListBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  {
      if(message == WM_MOUSEHOVER)
      {
          AfxMessageBox(_T("WindowProc: WM_MOUSEHOVER"));
      }
      return CListBox::WindowProc(message, wParam, lParam);
  }
  </code></pre>
  
  <p>Ok. So what I am missing? It's just not possible to capture this message in a global hook? Is there other way to make this without having to put the same code in every single control?</p>
  
  <p>Thanks.</p>
  
  <p>Javier</p>