开发者

How to obtain info of the program from the window list with CGWindowListCopyWindowInfo

I managed to get list of windows on the desktop with CGWindowListCopyWindowInfo, but the next time is to try to get the properties of the window, like the pro开发者_C百科gram name, title, and other properties.

What API should I look into and do we have any example on how to do this?


List the windows and retrieve the specific information while looping through:

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);
}

Available keys:

kCGWindowIsOnscreen
kCGWindowLayer 
kCGWindowMemoryUsage
kCGWindowName
kCGWindowNumber
kCGWindowOwnerName
kCGWindowOwnerPID
kCGWindowSharingState
kCGWindowStoreType
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜