Mac OS X 状态栏应用程序 - 从 Cmd/Alt 菜单中隐藏它?

发布于 2024-09-04 18:49:25 字数 755 浏览 2 评论 0原文

我正在尝试在 Obj-C/Cocoa 中创建一个简单的小状态栏应用程序。

所以我已经务实地完成了它 - 声明一个 NSStatusItem,将其添加到 NSStatusBar,然后给它一个 NSMenu 对象。有点像这样...

NSStatusBar *bar = [NSStatusBar systemStatusBar];

theItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[theItem retain];

[theItem setTitle: NSLocalizedString(@"Tablet",@"")];
[theItem setHighlightMode:YES];
[theItem setMenu:theMenu];

(示例取自“状态栏编程主题”,Apple 文档)

现在理想情况下,我希望此应用程序能够运行,并且无法从更改“菜单”的 CMD/ALT 窗口访问(因为缺少一个更好的词),我以前见过应用程序这样做,并且真的很喜欢。我的想法是我只是希望它可以从每个窗口访问,同时状态栏上没有自己的 NSMenu,并且无法将其作为活动应用程序( - 所以它无法接管整个状态栏,并且无法通过 CMD/ALT 看到)

此外,我想知道 StatusBarItem 是否支持将项目拖放到其上的功能?我不确定这是否是 NSStatusBar 的限制。

我已经阅读了有关守护进程和代理的内容,但这对于如此简单的应用程序来说似乎级别太低/过度杀戮!

提前干杯!

I'm trying to whip up a simple little Status Bar Application in Obj-C/Cocoa.

So I have done it pragmatically - declaring an NSStatusItem, adding it to the NSStatusBar and then giving it a NSMenu object. A bit like this...

NSStatusBar *bar = [NSStatusBar systemStatusBar];

theItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[theItem retain];

[theItem setTitle: NSLocalizedString(@"Tablet",@"")];
[theItem setHighlightMode:YES];
[theItem setMenu:theMenu];

(Example taken from "Status Bar Programming Topics", Apple Documentation)

Now ideally, I'd like this application to run and not be accessible from the CMD/ALT window changing "menu" (for lack of a better word), I've seen applications do it before and would like that really. The idea is I just want it to be accessible from every window, whilst not having its own NSMenu on the status bar, and whilst not being able to have it as the active application ( - so its not able to take over the whole Status Bar, and its not able to be seen through CMD/ALT)

Additionally, I was wondering if the StatusBarItem supports the ability to drag-n-drop an item onto it? I'm not sure if thats a limitation of the NSStatusBar though.

I've read up on deamons and agents, but that seems far too low level/over kill for such a simplistic app!

Cheers in advance!

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

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

发布评论

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

评论(1

世俗缘 2024-09-11 18:49:25

LSUIElement 键放入应用程序的 info.plist 中。要进行拖放,您可以将状态项的视图设置为应接收拖放的任何视图,并且从那时起它就可以正常工作。

Put the LSUIElement key in your app's info.plist. To do drag and drop, you set the status item's view to whatever view should receive the drop and it works normally from there on out.

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