title: Which API can be used to _capture_ the mouse when moving OS X "Carbon" windows?
body: <p>On request I have implemented support for moving an OS X window by dragging it using an area within the content part of the window, i.e replicating the drag and move functionality of the title bar but in another area. </p>
  
  <p>The problem I have yet to resolve is the fact that if the user drags the mouse quickly it can leave the window area and then no more mouse move events are received. </p>
  
  <p>On windows this type of problem can simply be fixed by calling the win32 method SetCapture(), what's the corresponding OSX method?</p>
  
  <p>This application is a cross platform C++ application using Carbon for the OS X specific parts. (And yes, I know all about the Cocoa benefits but this is an older code base and there no time nor money for a Cocoa port at this point in time.)</p>
  
  <p>I have found Carbon API methods like for example TrackMouseLocation() but can't really see how I could use them for this application. In listing 2-7 here <a href="http://developer.apple.com/legacy/mac/library/documentation/Carbon/Conceptual/Carbon_Event_Manager/Tasks/CarbonEventsTasks.html" rel="nofollow noreferrer">http://developer.apple.com/legacy/mac/library/documentation/Carbon/Conceptual/Carbon_Event_Manager/Tasks/CarbonEventsTasks.html</a> 
  the mouse is captured but the problem is that TrackMouseLocation() blocks waiting for input.  Blocking is something this application can not do since it also host a flash player that must be called many times per second.</p>
  
  <p>The protototype I have assembled when trying to figure this out basically looks like this:</p>
  
  <pre><code>switch(GetEventKind(inEvent))
  {
    case kEventMouseDown:
      // A silly test to make parts of the window border "draggable"
      dragging = local_loc.v &lt; 25 || local_loc.h &lt; 25; 
      last_screen_loc = screen_loc;
      break;
    case kEventMouseUp:
      dragging = false;
      break;
    case kEventMouseMoved:
      break;
    case kEventMouseDragged:
      if (dragging) {
        Rect rect;
        GetWindowBounds (windowRef, kWindowContentRgn, &amp;rect);
        int dx = screen_loc.h - last_screen_loc.h;
        int dy = screen_loc.v - last_screen_loc.v;
        rect.left += dx;
        rect.right += dx;
        rect.top += dy;
        rect.bottom += dy;
        SetWindowBounds (windowRef, kWindowContentRgn, &amp;rect);
      }
      last_screen_loc = screen_loc;
      break;
  </code></pre>
  
  <p>Any ideas appreciated?</p>