2

在我的应用程序中,我想检查其他应用程序的窗口是否可调整大小。

正如 Peter Hosey 在这个问题中回答的那样,我正在使用辅助功能 API 来测试窗口是否具有 kAXGrowAreaAttribute 属性(如果 NULL 不可调整大小)。

问题是 kAXGrowAreaAttribute 返回的值始终为 NULL,无论窗口是否可调整大小都无关紧要。注意:要检索值,我使用 Apple UIElementInspector示例中的 UIElementUtilities 类(我也尝试过直接使用 AXUIElementCopyAttributeValue 并获得相同的结果)。

任何想法?我在Lion工作,可能是这个问题吗?提前致谢。

编辑:

玩弄 UIElementUtilities 类方法,我找到了解决方案。

只需使用方法

+ (BOOL)canSetAttribute:(NSString *)attributeName ofUIElement:(AXUIElementRef)element

使用 kAXSizeAttribute 和焦点窗口。它返回 YES 或 NO 取决于窗口是否很大...

4

2 回答 2

2

It probably is because you're in Lion. The size box was killed off; resizable windows are resizable at every edge now.

And yes, testing whether the size can be changed is probably the right way. It seems to work for me in Snow Leopard.

于 2011-11-28T21:53:22.740 回答
0

斯威夫特 5 版本

func isResizable(axElement: AXUIElement) -> Bool {
    var resizable: DarwinBoolean = true
    let status = AXUIElementIsAttributeSettable(axElement, kAXSizeAttribute as CFString, &resizable)

    if status != .success {
        print("unable to determine if window is resizable")
    }
    return resizable.boolValue
}
于 2020-01-14T14:53:44.367 回答