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

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

问题描述

我是 Cocoa 开发新手,正在开发我的第一个应用程序.我想从任何应用程序的任何窗口读取唯一标识符 - 无论是 Cocoa 还是 Carbon.Cocoa 应用程序使它们的窗口 ID 可用于 AppleScript(虽然我确信有更好的方法通过适当的 Objective C 路由来做到这一点),但我正在尝试从 Adob​​e 应用程序中的文档访问窗口 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 键将作为 CFNumber 指向窗口 ID.还有一个 CGWindowListCreate() 函数,它只返回一个 CGWindowID 数组.除了 CGWindow.h 标头和 Grab 之子 示例代码.此外,它只有 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天全站免登陆