title: Take screenshots of specific application window on Mac
body: <p>I'm trying to make a screen cast application which casts individual application windows instead of the whole screen. To start with I'm trying to take simple screenshots of individual applications on my mac using Xcode. </p>
  
  <p>So far, I'm trying to make use of <code>CGWindowListCreateImage</code> but I'm running into problems.</p>
  
  <p><strong>EDIT</strong>
  So here's a small example of how I managed to get the WindowID. It's pretty simple afterwards to take a screenshot using it.
  First you add a global monitor for events, more specifically NSMouseEvents. I used mouse down. The window information is stored in the mouse event.</p>
  
  <pre><code>    CGWindowID windowID = (CGWindowID)[event windowNumber];
  </code></pre>
  
  <p>You can then take a screenshot of JUST the app, without shadows etc using the code below.</p>
  
  <pre><code>CGImageRef image = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, self.WindowID, kCGWindowImageBoundsIgnoreFraming);
  </code></pre>
  
  <p>Let me know if you need more.</p>