Is it possible to hide the dock icon programmatically

喜夏-厌秋 提交于 2020-01-02 06:35:13

问题


Is it possible to hide dock icon programmatically on demand. I know one way by which defining property "Application is agent (UIElement)" in plist we make the cocoa app as user agent. But this result in hiding the dock icon permanently.

I am looking for a way where i can control visibility of dock icon. Any idea ?


回答1:


Unfortunately not. You can transform a background-only app to a foreground app using the TransformProcessType() function but you can't go from a foreground app to a background app.

Here's how to go from background to foreground:

ProcessSerialNumber psn = { 0, kCurrentProcess }; 
OSStatus returnCode = TransformProcessType(&psn, kProcessTransformToForegroundApplication);
if( returnCode != 0) {
    NSLog(@"Could not bring the application to front. Error %d", returnCode);
}


来源:https://stackoverflow.com/questions/2832961/is-it-possible-to-hide-the-dock-icon-programmatically

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