通过NSRunningApplication实例获取应用程序的主窗口 [英] Getting the main window of an app via an NSRunningApplication instance

查看:434
本文介绍了通过NSRunningApplication实例获取应用程序的主窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观察NSWorkspaceDidDeactivateApplicationNotification通知,即可刚刚失去焦点的应用程序.我最后得到了一个N​​SRunningApplication实例,该实例是从通知对象的userInfo字典键-NSWorkspaceApplicationKey中获得的.

I'm observing NSWorkspaceDidDeactivateApplicationNotification notification to get the application that has just lost focus. I'm ending up with an instance of NSRunningApplication which you get from the userInfo dictionary key - NSWorkspaceApplicationKey - of the notification object.

我当时想我可以从通知中的应用程序中获取主窗口,但由于NSRunningApplication似乎非常有限,因此我不确定从何处去.任何帮助将不胜感激.

I was thinking that I'd be able to get the main window from the app from the notification but I'm not sure where to go from here as NSRunningApplication seems to pretty limited. Any help would be appreciated.

顺便说一句-我正在使用MacRuby,但答案不一定是MacRuby.

BTW - I'm using MacRuby but the answer doesn't need to be in MacRuby.

谢谢

推荐答案

Apple一直以来都对这种事情颇为拘束. NSRunningApplication本身是在10.6中引入的,正如您所说的,它有点受限制.根据您要执行的操作,答案可能在 CGWindow API .您可以使用NSRunningApplication中的processIdentifier将其与这些API匹配.

Apple has traditionally been pretty locked-down about this sort of thing. NSRunningApplication itself was just introduced in 10.6, and as you said, it's a bit limited. Depending on what you want to do, the answer might be in the Accessibility framework or it might be the CGWindow API. You can use the processIdentifier from the NSRunningApplication to match it up with those APIs.

这篇关于通过NSRunningApplication实例获取应用程序的主窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆