我希望能够设置一个从外部应用程序(例如TextEdit)打开的窗口成为最前面的窗口。
我可以成功地使用GetFrontProcess获取应用程序自身的引用,并检查它是否是最前面的窗口。如果不是,我可以使用setFrontProcess使其获得焦点。
然后,我可以使用可访问性API来检查该应用程序下的所有窗口。我正在检查某个特定的窗口是否存在,如果存在,我会将其与该应用程序的最前面的窗口进行比较:
//get the front window of textEditApp and store it in 'currentFrontWindow'
AXUIElementCopyAttributeValue(textEditApp, kAXFocusedWindowAttribute, (CFTypeRef *)¤tFrontWindow);
如果我感兴趣的窗口不是最前面的,我需要将其设置为最前面的。我认为我可以使用AXUIElement Set AttributeValue来实现这一点,但是我没有成功。以下是我的尝试方式。
//set the front window of textEditApp to be desiredFrontWindow
AXUIElementSetAttributeValue(textEditApp, kAXFocusedUIElementAttribute, desiredFrontWindow);
我已检查到窗口存在,并且应用程序成功地进行了“切换到”。但为什么这行代码不能将指定的窗口置于最前面呢?
谢谢。