cocoa如何知道哪个窗口是前景
Mac OS X 上有类似 GetForegroundWindow 的东西吗?
我有两个应用程序,一个是窗口化的(基于 NSDocument 的),一个是命令行的。我想从命令行工具显示 NSOpenPanel,并希望使其成为基于 NSDocument 的应用程序的模型,但没有 windowref ?
Is there anything similar to GetForegroundWindow on Mac OS X?
I've two apps one windowed (NSDocument based) and one command line I want to show an NSOpenPanel from command line tool and would like to make it model for the NSDocument based app but don't have the windowref for it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要的东西存在一些问题。
首先,Mac 上的应用程序没有窗口引用。一个应用程序可以有任意数量的窗口。其次,在 Mac OS X 中对其他进程的窗口的访问受到限制。有一些 API 可以以不同的方式访问它们。无论如何,引用另一个应用程序的窗口将不允许您为该应用程序抛出模式对话框。
您想要的是让命令行应用程序与前台应用程序通信,告诉它显示打开的面板。您可以建立自己的通信协议(例如通过分布式对象),也可以使用 Apple Events/AppleScript 来回通信。
There are a few problems with what you want.
First of all, applications on the Mac do not have window references. An application may have any number of windows. Second, access to other processes' windows is limited in Mac OS X. There are a few APIs for accessing them in different ways. At any rate, having a reference to another app's window will not allow you to throw up modal dialogs for that application.
What you want is to have the command line app communicate with the foreground app to tell it to show the open panel. You could either establish your own communications protocol (e.g. through Distributed Objects) or you could use Apple Events/AppleScript to communicate back and forth.