title: How to detect drag in a mouse hook procedure
body: <p>I've successfully set up a mouse hook for a window, and I'd like to detect a drag operation when the left mouse button is clicked. I've tried using <a href="https://docs.microsoft.com/en-us/windows/win32/learnwin32/other-mouse-operations" rel="nofollow noreferrer"><code>DragDetect</code></a>, as shown below, but it never returns <code>TRUE</code>, and it never suppresses the subsequent mouse-up event (in this code, <code>hwnd</code> is the target window):</p>
  
  <pre><code>LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
  {
      if (nCode &lt; 0)
      {
          return CallNextHookEx(NULL, nCode, wParam, lParam);
      }
  
      switch (wParam)
      {
          case WM_LBUTTONDOWN:
          {
              // Get the click point
              LPMOUSEHOOKSTRUCT pMouseHookStruct = reinterpret_cast&lt;LPMOUSEHOOKSTRUCT&gt;(lParam);
              CPoint ptClick = pMouseHookStruct-&gt;pt;
  
              // Drag detect
              BOOL fDrag = DragDetect(hwnd, ptClick);
              if (fDrag)
              {
                  MessageBox(NULL, L"Drag", NULL, MB_OK);
              }
          break;
          }
      }
      return CallNextHookEx(NULL, nCode, wParam, lParam);
  }
  </code></pre>
  
  <p>Does <code>DragDetect</code> not work within hook procedures, or am I just doing something wrong?</p>