How to get Window reference (CGWindow, NSWindow or WindowRef) from CGWindowID in Swift?

ε祈祈猫儿з 提交于 2020-01-04 05:34:08

问题


How to get Window reference (CGWindow, NSWindow or WindowRef) from CGWindowID in Swift on XCode 7.3 Mac Playground?

I referenced from Apple's document - Window Manager Reference, and from the sample code SonofGrab, but I didn't find an answer in obj-C nor Swift.

How should I do it?


回答1:


This should work for NSWindow from CGWindowID

NSWindow * ns_window;
ns_window = [NSApp windowWithWindowNumber: windowNumber];

To get CGWindowID from NSWindow use

CGWindowID window_id = (CGWindowID)[ns_window windowNumber];


来源:https://stackoverflow.com/questions/38801195/how-to-get-window-reference-cgwindow-nswindow-or-windowref-from-cgwindowid-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!