如何将Carbon AXUIElementRef转换为Cocoa NSWindow

时间:2015-09-18 02:42:40

标签: cocoa macos-carbon

在我的项目中,我可以获得鼠标所在的窗口,我可以使用AXUIElementSetAttributeValue(element, kAXFrontmostAttribute, kCFBooleanTrue);  使窗口暂时达到顶层。所以我想将元素转换为Cocoa NSWindow,然后使用makeKeyAndOrderFront使它始终在前面。任何人都知道如何实现这一点。

+ (NSArray *)attributeNamesOfUIElement:(AXUIElementRef)element {
    NSArray *attrNames = nil;
    AXUIElementCopyAttributeNames(element, (const void*)&attrNames);

    AXUIElementSetAttributeValue(element, kAXFrontmostAttribute, kCFBooleanTrue);

    // Below lines doesn't work.
    HIObjectRef windowref=AXUIElementGetHIObject(element);
    NSWindow *cocoaWindow = [[NSWindow alloc]initWithWindowRef:windowref];

    return attrNames;
}

0 个答案:

没有答案