获取另一个应用程序的窗口的唯一ID [英] Getting a unique ID for a window of another application

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

问题描述

我是一个新手Cocoa开发人员,我正在开发我的第一个应用程序。我想从任何应用程序的任何窗口读取唯一标识符 - 无论是Cocoa还是Carbon。 Cocoa应用程序使他们的窗口ID可用于AppleScript(虽然我确信有一个更好的方法来通过一个适当的Objective C路由),但我试图从Adobe应用程序中的文档访问窗口ID。这似乎是很多棘手。我在参考库中找到的所有内容都是 HIWindowGetCGWindowID

I'm a newbie Cocoa developer and I'm developing my first application. I want to read a unique identifier from any window of any application - whether it's Cocoa or Carbon. Cocoa applications make their window IDs available to AppleScript (although I'm sure there's a much better way to do this through a proper Objective C route), but I'm trying to access window IDs from documents in the Adobe apps. This seems to be a lot trickier. All I can seem to find in the reference libraries is HIWindowGetCGWindowID:

此函数返回窗口服务器在创建窗口时分配的窗口ID。窗口ID通常不与任何其他Carbon函数一起使用,但可以与需要窗口ID的其他Mac OS X函数(例如OpenGL中的函数)一起使用。

"This function returns the window ID assigned by the window server when a window is created. The window ID is not generally useful with any other Carbon function, but may be used with other Mac OS X functions that require a window ID, such as functions in OpenGL."

用于从我的程序获取ID?或者它只是一个可以在一个应用程序中使用的函数?

Can this be used to get the ID from my program? Or is it just a function that can be used within one application?

如果有人能指出正确的方向,我会永远感激。

If someone could point me in the right direction, I'd be eternally grateful.

推荐答案

函数HIWindowGetCGWindowID()只能返回一个应用程序的窗口的CGWindowID,因为来自另一个程序的WindowRef将无效

The function HIWindowGetCGWindowID() can only return a CGWindowID for one of your app's windows, since a WindowRef from another program won't be valid in yours.

CGWindow.h中的函数CGWindowListCopyWindowInfo()将返回一个字典数组,每个窗口符合您设置的标准,包括其他应用程序中的标准。它只允许你过滤一个给定的窗口,给定窗口下面的窗口和屏幕窗口,但返回的字典包含一个进程ID的拥有应用程序,你可以使用它来匹配窗口到应用程序。在每个返回的字典中,kCGWindowNumber键将指向窗口ID作为CFNumber。还有一个CGWindowListCreate()函数,只返回一个CGWindowID数组。除了CGWindow.h标头和抓斗之子之外,基本上没有这些功能的文档'示例代码。此外,它只有10.5。

The function CGWindowListCopyWindowInfo() from CGWindow.h will return an array of dictionaries, one for each window that matches the criteria you set, including ones in other applications. It only lets you filter by windows above a given window, windows below a given window and 'onscreen' windows, but the dictionary returned includes a process ID for the owning app which you can use to match up window to app. In each returned dictionary the kCGWindowNumber key will point to the window ID as a CFNumber. There is also a CGWindowListCreate() function that only returns an array of CGWindowIDs. There is basically no documentation for these functions beyond the CGWindow.h header and the 'Son of Grab' sample code. Also, it's 10.5 only.

这篇关于获取另一个应用程序的窗口的唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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