Reputation: 141
how can i get current focused window id using objective c, the return value should be an int, help is highly appreciated! I just need to get the following line working
CGImageRef windowImage = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, winNum, kCGWindowImageBoundsIgnoreFraming);
but no matter which window that i focus at, winNum is always 0.
Upvotes: 0
Views: 3930
Reputation: 12107
NSWindow *keyTarget = [[NSApplication sharedApplication] keyWindow];
NSInteger winNum = [keyTarget windowNumber];
or in one line:
[[[NSApplication sharedApplication] keyWindow] windowNumber];
Upvotes: 7