Get application icon from ProcessSerialNumber

…衆ロ難τιáo~ 提交于 2020-01-04 02:38:07

问题


I would like to get the application icon for all foreground applications running on my Mac. I'm already iterating over all applications using the Process Manager API. I have determined that any process that does not have the modeBackgroundOnly flag set in the processMode (as retrieved from GetProcessInformation()) is a "foreground" application, and shows up in the task switcher window.

All I need is an API that gives me a CImageRef (or similar) that contains the application icon for a process. I'm free to use either carbon or cocoa APIs.


回答1:


On Mac OS X 10.6 or later, you can ask a running application for its icon.

On earlier versions of Mac OS X, you'll have to get it by looking at the application's bundle. Pass the PSN to the GetProcessBundleLocation function to get the bundle's location as an FSRef, then pass that to the GetIconRefFromFileInfo function.




回答2:


You can use the LaunchServices functions (Carbon) or the NSWorkspace class (Cocoa).



来源:https://stackoverflow.com/questions/2453318/get-application-icon-from-processserialnumber

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