I mean all the windows which belong to my application (process). I need to get something like (NSWindow *) for all of them. Notice, some windows were created by third-party plug-ins and are not accessible by [NSApp windows]. Yes, I know, Quartz Window Services can return all the windows by PID. But how can I get NSWindow by CGWindowID then? Thanks!
+2
A:
Try NSWindowList
to get window numbers, and then -[NSApplication windowWithWindowNumber:]
to get NSWindows.
JWWalker
2010-06-21 21:27:30
NSWindowList returns correct number of windows from all applications, but windowWithWindowNumber (Cocoa) and HIWindowFromCGWindowID (Carbon) return nil.
iUm
2010-06-22 12:30:55
This is the right answer -- NSWindowList returns all windows for all processes, so if windowWithWindowNumber returns nil it means that the window doesn't belong to your application. NSWindowListForContext returns only the windows for a particular process, but you need to call a private method ([NSApp contextID]) to pass in the the context ID for your running application.
Scott K.
2010-08-03 21:50:48
A:
Usually NSWindowList() will give window ids. Also there're Quartz Window Services to help.
To get NSWindow* (Cocoa) there's [NSApp windowWithWindowNumber: (NSInteger)windowID] method. To get WindowRef (Carbon) there's HIWindowFromCGWindowID() function.
If both of them does not work, that means the window was created with CoreGraphics Private API. Its definition is available thanks to reverse engineering.
Concerning X11 windows on Mac, they are created with Xplugin library (by Xquartz) which is closed source and also uses CoreGraphics Private API.
iUm
2010-06-30 13:19:22