4

I've got an application that runs at startup as a menu in the OS X menu bar (i.e., as a background application). When you select an option from the menu, it transforms into a foreground application (creating a dock icon) and shows a window.

Here's the background/foreground code I'm using:

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

+(void) TransformToBackgroundApplication {
    ProcessSerialNumber psn = { 0, kCurrentProcess };
    TransformProcessType(&psn, kProcessTransformToUIElementApplication);
}

Pretty standard stuff, from the looks of things. And it works fine, except for one small issue.

The problem is that after I call TransformToForegroundApplication, I call makeKeyAndOrderFront: on the window to make it come to the front of the Z-order and receive focus - but it does neither. It shows up in the background, underneath everything else. I need to either click on the dock icon, or minimize all of the windows in front of it and then click on that window, in order to bring it to the front.

Any ideas?

4

1 回答 1

5

可能您需要激活应用程序,我认为TransformProcessType()这不会自动执行,并且知道-makeKeyAndOrderFront:不会。

你试过打电话[NSApp activateIgnoringOtherApps:YES]吗?

于 2013-07-17T04:58:27.917 回答