Leopard brings new APIs at the CoreGraphics layer to gather information about windows on the system. These functions let you find windows relative to a known window, find all windows on the system, including those offscreen, and obtain images of one or more windows as composited by the Window Server.
However, these API's have an interesting peculiarity: when the documentation says "a CFArray of CGWindowID values" they mean a CFArray of uint32s, not CFNumbers as programmers familiar with CoreFoundation might expect. This holds true for the
CGWindowListCreateImageFromArray functions, but the two functions that return window information (
CGWindowListCreateDescriptionFromArray()) wrap all numeric values in CFNumbers.
To create such an array, you'll have to create it with CFArrayCreateMutable(), such as the following:
/* Make an array with no callbacks */ CFMutableArrayRef windows = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL); /* myWindow is a NSWindow */ CFArrayAppendValue(windows, (void *)[myWindow windowNumber]);
To get the
CGWindowID of a
NSWindow, you'll want to use
-[NSWindow windowNumber]. Even though the documentation specifies that this isn't the same number as assigned by the WindowServer, it turns out that it works fine with the CGWindow* APIs.