views:

45

answers:

0

hi all,

i'm trying to take a screenshot on osx with c/c++ so far this is what i got:

#import <ApplicationServices/ApplicationServices.h>

int main( int argc, char** argv) {
  CGImageRef screenShot = CGWindowListCreateImage( CGRectInfinite,
      kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);

  CFStringRef file = CFSTR("/Users/aduh/Desktop/lala.jpg");
  CFStringRef type = CFSTR("public.jpeg");
  CFURLRef urlRef = CFURLCreateWithString( NULL, file, NULL );
  CGImageDestinationRef idst = CGImageDestinationCreateWithURL( urlRef, type, 1, NULL );
  CGImageDestinationAddImage( idst, screenShot, NULL );
  CGImageDestinationFinalize( idst );}

it compiles fine but nothing really happens im probably just making a stupid mistake so if anyone can point me in the right direction that would be great!!

thanks in advance!