How to convert a Carbon AXUIElementRef to Cocoa NSWindow

老子叫甜甜 提交于 2019-12-04 06:30:01

问题


In my project, i can get the window which mouse is on, and i can use AXUIElementSetAttributeValue(element, kAXFrontmostAttribute, kCFBooleanTrue); to make the window to top level temporarily. So i want to convert the element to Cocoa NSWindow and then use makeKeyAndOrderFront to make it always in front. Anyone know how to implement this.

+ (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;
}

来源:https://stackoverflow.com/questions/32642999/how-to-convert-a-carbon-axuielementref-to-cocoa-nswindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!