Cocoa - Get window ID on click, as used in Grab

Discussion in 'Mac Programming' started by JBurke, May 4, 2009.

  1. JBurke macrumors newbie

    Joined:
    May 4, 2009
    #1
    Hey everyone, I have been searching for this answer and I realized that I don't even really know what to search for. Here's what I'm trying to do, and maybe someone can give me at least what to search for, if not the answer itself!

    I'm building a Cocoa app right now in which I want to be able to click any window that is open and get the process serial or any kind of window ID number that I can compare to other windows. This is similar to the functionality of the Grab screen-shot utility that comes with OS X.

    If you open Grab, then select Capture->Window, it comes up with a message box and you click "Choose Window", and the cursor becomes a camera, and any window you click while it is a camera is what Grab takes the screenshot of. I want to be able to click a window and return its ID. Any thoughts??

    Any and all help is greatly appreciated!
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    This should be doable with the CGWindow API in Leopard (spotlight "CGWindow.h"). You'll have to loop through all the windows, and find the top one whose bounds contains the mouse location.
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    Worst case scenario you could ktrace grab and see what sorts of things it's doing when you take a screenshot with it. It may not be using public APIs, but you should be able to see the calls it's making and look any up that look "interesting".

    -Lee
     
  4. JBurke thread starter macrumors newbie

    Joined:
    May 4, 2009
    #4
    @kainjow, thanks alot! I will check that out and see if it can do exactly what I need. Just reading glancing over that header file makes me think it will do nicely.

    @lee1210, I'll definitely keep that in mind, and that's where I'm going if CGWindow doesn't exactly cut it. Thanks again for the speedy help!
     

Share This Page