将LSUIElement转换为前台应用程序 [英] Transform LSUIElement to foreground application

查看:102
本文介绍了将LSUIElement转换为前台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个必须始终运行的应用程序(如果用户同意的话)。

I have an app which must run all the time (if the user agree whit this).

当用户退出该应用程序时,我会将前台应用程序转换为LSUIElement(该应用仅具有菜单栏图标,停靠图标和菜单消失)。

When the user quit the app, I transform the foreground app into a LSUIElement (the app only has a menu bar icon, the dock icon and the menu disappear).

我在菜单项中有一个选项,可以正常运行并转换LSUIElement进入前台应用程序(我使用功能 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] [NSApp activateIgnoringOtherApps:YES]

I have an options in the menu item which works ok and transform the LSUIElement into a foreground app (I use the functions [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] and [NSApp activateIgnoringOtherApps:YES]).

我的问题出现在用户双击应用程序时。我在委托方法 applicationWillUnhide:(NSNotification *)notification 中再次使用 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] 除了没有出现的菜单外,其他都可以正常工作。如果我转到另一个应用程序,然后又回来,则显示菜单。我尝试了不同的方法,但找不到合适的方法。

My problem appear when the user double click on the app. I use again the [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] in the delegate method applicationWillUnhide:(NSNotification *)notification, and all works well except the menu which doesn't appear. If I go to another app, and then I came back the menu appear. I try different methods but I wasn't able to find a good one.

我想知道是一个委托方法,当用户双击应用程序时会调用该方法,或者在那一刻被调用的 NSApplication 中的函数是什么,因为我认为使用 setActivationPolicy: applicationWillUnhide 函数太迟了。

I want to know is a delegate method which is called when the user double clicks on the app, or what is the function from NSApplication which is called in that moment, because I think using the setActivationPolicy: in the applicationWillUnhide function is to late.

推荐答案

将普通应用程序转换为我使用的LSUIElement

To transform a normal application to a LSUIElement I use

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

并将其更改回前台:

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

这篇关于将LSUIElement转换为前台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆