如何使用CGWindowListCopyWindowInfo从窗口列表中获取程序的信息

时间:2011-05-28 09:17:39

标签: cocoa nswindow

我设法通过CGWindowListCopyWindowInfo获取桌面上的窗口列表,但下一次是尝试获取窗口的属性,如程序名称,标题和其他属性。

我应该查看哪些API,我们是否有任何关于如何执行此操作的示例?

1 个答案:

答案 0 :(得分:6)

列出窗口并在循环时检索特定信息:

NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);

for (NSDictionary *window in windows) {
    NSString *owner = [window objectForKey:@"kCGWindowOwnerName" ];
    NSString *name = [window objectForKey:@"kCGWindowName" ];
    NSLog(@"%@ - %@",owner,name);
}

可用键:

kCGWindowIsOnscreen
kCGWindowLayer 
kCGWindowMemoryUsage
kCGWindowName
kCGWindowNumber
kCGWindowOwnerName
kCGWindowOwnerPID
kCGWindowSharingState
kCGWindowStoreType