NSRunAlertPanel shows up behind the “active window”

北城余情 提交于 2019-12-06 08:39:58

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!