简体   繁体   中英

Is it possible to show the dock icon when a new Window is called?

I have an app that's shown as a Menu on the Status Bar, so I switched the "Application is agent (UIElement)" in plist to YES (because I dont want an icon on the dock just for a Menu on the Status Bar), but when I click an Item on the Menu a new window is called, is it possible to make a dock icon appear for that window? and disappear when the window is closed?

You will need to create a separate application binary/bundle to display that window. There is no supported way for an application to cause a Dock icon to be displayed on anything other than a per-process basis, or to dynamically hide/show the Dock icon while it's running.

您可以使用NSRunningApplication + DockIcon显示和隐藏应用程序的Dock图标,但要注意,此代码使用未记录的API。

To set your application to be a foreground application, which causes its icon to appear in the Dock, and the app to appear in the Cmd+Tab list:

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

And to change it back again:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM