Carbon、LSUIElement 和显示窗口
我有一个 Carbon LSUIElement 应用程序,它在后台运行(可能在菜单栏中有一个图标,具体取决于首选项),偶尔需要向用户显示一个对话框 - 有时响应用户事件,但有时响应后台任务失败或类似情况。
(我使用的是 Qt 4.5,所以应用程序是基于 Carbon 的;使用 Qt 4.6 时,事情将基于 Cocoa,但听起来好像问题也可能存在)。
问题是,当我打开一个窗口并显示它时,它不会被带到前面。我认为这是 LSUIElement 应用程序的一个艺术作品。 Qt 在 Carbon 中使用 SelectWindow,在 Cocoa 中使用 [makeKeyAndOrderFront],将窗口(和应用程序)置于最前面。
为了解决这个问题,我尝试直接访问窗口服务器:(前几个步骤是获取 WindowID,这对于 Qt-Cocoa 来说会更简单,因为我可以使用 NSWindow:nativeWindow)
WindowRef ref = HIViewGetWindow((HIViewRef) aWidget->winId());
CGSWindow wid = GetNativeWindowFromWindowRef(ref);
CGSConnection cid =_CGSDefaultConnection();
CGSOrderWindow(cid, wid, 1 /* above everything */, 0 /* NULL */);
这可以工作,有点 -窗口出现在前面,但它没有突出显示或键盘聚焦。是否有其他步骤来解决这些问题,或者是否有更简单的解决方案来解决整个问题?
I have a Carbon LSUIElement application, which runs in the background (possibly with an icon in the menubar, depending on a pref) and occasionally needs to show a dialog to the user - sometimes in response to a user event, but sometimes in response to a background task failing or similar.
(I'm using Qt 4.5, so the application is Carbon based; With Qt 4.6 things will be Cocoa based, but it sounds as if the problem may exist there too).
The problem is that when I open a window, and show it, it doesn't get brought to the front. I assume this is an artefect of being an LSUIElement app. Qt uses SelectWindow in Carbon, and [makeKeyAndOrderFront] in Cocoa, to bring a window (and the app) to the front.
To work around the problem, I tried going direct to the window server: (the first few steps are to get the WindowID, this will be simpler with Qt-Cocoa, since I can use NSWindow:nativeWindow)
WindowRef ref = HIViewGetWindow((HIViewRef) aWidget->winId());
CGSWindow wid = GetNativeWindowFromWindowRef(ref);
CGSConnection cid =_CGSDefaultConnection();
CGSOrderWindow(cid, wid, 1 /* above everything */, 0 /* NULL */);
This works, sort of - the window comes to the front, but it's not highlighted or keyboard focused. Are there additional steps to fix those issues, or is there a simpler solution to the whole problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 SetFrontProcessWithOptions 将您的窗口置于其他应用程序的前面。
Use SetFrontProcessWithOptions to bring your window in front of other apps.
尝试:
Try: