NSRunAlertPanel 显示在“活动窗口”后面

发布于 2024-08-29 09:13:36 字数 617 浏览 3 评论 0原文

我正在尝试整理一个简单的错误报告包。如果我的主程序崩溃,它会保存崩溃日志,然后启动报告程序。报告程序询问用户是否可以将崩溃日志发送给我,然后就这样做了。我正在使用 NSRunAlertPanel 创建一个基本消息框。

由于某种原因,该消息框显示在任何其他可能打开的窗口下方。从 Finder 窗口运行主包,它显示在顶部,强制它崩溃,报告器窗口显示在 Finder 窗口后面

为什么会出现这种情况,如何解决?

最小测试用例:

#import <AppKit/AppKit.h>

int main(int a, char* av) {
  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  NSApplication* q = [[NSApplication alloc] init]; 
  NSRunAlertPanel(@"Hello", @"Aloha", @"OK", nil,nil);
  [pool release];
} 

构建于:

g++ test.mm -framework AppKit && ./a.out

I'm trying to put together a simple error reporting package. If my main program crashes, it saves a crashlog, then starts a reporter program. The reporter program asks the user if it can send the crash log to me, then does so. I'm using NSRunAlertPanel to create a basic message box.

For some reason, that message box is showing up buried underneath any other windows that may be open. Run the main package from a Finder window, it shows up on top, force it to crash, the reporter window shows up behind the Finder window.

Why is this happening, and how can it be solved?

Minimal test case:

#import <AppKit/AppKit.h>

int main(int a, char* av) {
  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  NSApplication* q = [[NSApplication alloc] init]; 
  NSRunAlertPanel(@"Hello", @"Aloha", @"OK", nil,nil);
  [pool release];
} 

Built with:

g++ test.mm -framework AppKit && ./a.out

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捎一片雪花 2024-09-05 09:13:36

我似乎已经想出了一个解决方案,从许多与切线相关的网页中提炼出来:

#import <AppKit/AppKit.h>

int main(int a, char* av) {
  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  NSApplication* q = [[NSApplication alloc] init]; 

  ProcessSerialNumber psn = {0, kCurrentProcess};
  TransformProcessType(&psn, kProcessTransformToForegroundApplication);

  [NSApp activateIgnoringOtherApps:YES];

  NSRunAlertPanel(@"Hello", @"Aloha", @"OK", nil,nil);
  [pool release];
} 

我并不假装理解这一点 - 这是最好的货物崇拜编程。更好的答案或每个步骤的作用的解释将不胜感激。

I seem to have come up with a solution, distilled from many tangentially-related webpages:

#import <AppKit/AppKit.h>

int main(int a, char* av) {
  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  NSApplication* q = [[NSApplication alloc] init]; 

  ProcessSerialNumber psn = {0, kCurrentProcess};
  TransformProcessType(&psn, kProcessTransformToForegroundApplication);

  [NSApp activateIgnoringOtherApps:YES];

  NSRunAlertPanel(@"Hello", @"Aloha", @"OK", nil,nil);
  [pool release];
} 

I do not pretend to understand this - it's cargo cult programming at its finest. Better answers, or explanations of what each step does, would be greatly appreciated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文