gpt4 book ai didi

macos - 如何获取事件空间上每个可见窗口的框架(原点、大小)?

转载 作者:行者123 更新时间:2023-12-03 17:31:59 26 4
gpt4 key购买 nike

我试图弄清楚如何获取所有可见窗口的框架。我尝试了以下代码,但它仅适用于应用程序本身,其他窗口报告 {0,0,0,0}

   NSArray *windowArray =  [NSWindow windowNumbersWithOptions:NSWindowNumberListAllApplications | NSWindowNumberListAllSpaces];
for(NSNumber *number in windowArray){
NSLog(@"Window number: %@", number);
NSWindow *window = [[NSApplication sharedApplication] windowWithWindowNumber:[number intValue]];
NSLog(@"Window: %@", NSStringFromRect( [[window contentView] frame]));
}

示例代码值得赞赏。

最佳答案

我明白了:

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

for (NSDictionary *window in windows) {
NSString *name = [window objectForKey:@"kCGWindowName" ];
CGRect bounds;
CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:@"kCGWindowBounds"], &bounds);
NSLog(@"%@: %@",name,NSStringFromRect(bounds));
}

关于macos - 如何获取事件空间上每个可见窗口的框架(原点、大小)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10207291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com