How to convert a Carbon AXUIElementRef to Cocoa NSWindow
Asked Answered
A

0

0

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;
}
Appurtenance answered 18/9, 2015 at 2:42 Comment(5)
You might be interested in this post.Antarctica
One app can't have an NSWindow* that refers to the window of another app. Apps can only directly manipulate the windows of their own process. If a given window is the frontmost of its owning app, you can activate that app using NSRunningApplication and that will bring the window forward.Hf
Is AXUIElementRef Carbon?Interclavicle
Ah, HIObjectRef is Carbon.Interclavicle
makeKeyAndOrderFront doesn't make a window always in front, it just brings it to the front. What are you trying to do?Interclavicle

© 2022 - 2024 — McMap. All rights reserved.