Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JBurke

macrumors newbie
Original poster
May 4, 2009
2
0
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!
 
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.
 
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
 
@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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.