tags:

views:

122

answers:

3

I need to host my window upon a window of another application. How to enumerate windows of another Cocoa application? Is it possible to control them? If no: how can I draw upon a window of another application? Thanks!

+2  A: 

How to enumerate windows of another Cocoa application?

You can enumerate the windows of another application using the Accessibility API. It doesn't matter whether that application is Cocoa or not.

Is it possible to control them?

Here, it does matter, indirectly, whether the application is Cocoa (or Carbon using standard controls). More precisely, it matters whether the application is accessible.

It usually is possible to move another window, resize it, or do simple things with controls in it (such as press buttons).

It is not possible to tape one of your windows to a window in another application. You will have to observe its location and move your window when the other moves. Following a live drag this way is not possible.

If no: how can I draw upon a window of another application?

You can't. You can only draw in your own windows.

You can make a transparent overlay window and draw on that, but that gets you back to the problem of taping one of your windows to a window in another application.

You should probably ask a broader question about whatever it is you hope to achieve by taping one of your windows to a window in another application or by drawing into a window in another application.

Peter Hosey
Thank you, Peter!I'll make a suggestion: can I lay out my borderless window in such a way so that it would be displayed exactly in some place (I mean definite x and y coords from the top left corner) of another active window, would move and hide with it so that the user will think it's really hosted upon it?
iUm
I answered that in the second third of my answer.
Peter Hosey
A: 

Cocoa does not support reparenting of another application window, or drawing on it.

But, there're two ways to get windows attributes for all the applications, like position, size, z-order, etc.

  1. Accessibility API (also allows to control a foreign application window: move, resize, press buttons on it, etc.). If a foreign application does not support Accessibility API, then...
  2. Quartz Window Services and a sample code for them, called "Son of Grab".
iUm
Neither of these solutions can truly tape one window to another; the Accessibility API does not provide live updates as drags happen, and Quartz Window Services does not provide any sort of window-move or -resize notification at all.
Peter Hosey
A: 

Checkout CGWindow.h

CGWindowListCreateDescriptionFromArray() is probably what you're looking for.

Leibowitzn
Yes, that is a part of Quartz Window Services.
iUm