我想知道屏幕上可以看到哪些窗口。CGWindowListCopyWindowInfo 给了我窗口列表,这很好,除了它还列出了最小化的窗口。我尝试使用 kCGWindowIsOnscreen 来检测隐藏/最小化的窗口,但它总是为所有窗口提供 TRUE。有没有办法以某种方式检测到这一点?
- (void) checkWindows {
NSMutableArray *windows = (__bridge NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
for (NSDictionary *window in windows) {
NSString *owner = [window objectForKey:@"kCGWindowOwnerName" ];
NSString *name = [window objectForKey:@"kCGWindowName" ];
CFBooleanRef visibleBR = (CFBooleanRef)[window objectForKey:@"kCGWindowIsOnscreen"];
bool visible = CFBooleanGetValue(visibleBR);
NSLog(@"%@,%@,Visible:%@",owner,name,visible?@"YES":@"NO");
}
}
更新:很奇怪,这只是微软的话。事实上,它不必隐藏,Word 会创建一个全屏窗口,该窗口不可见,但列在可见窗口中。