开发者

get app icon from window id in cocoa

I am looking for a way to get the application icon from a window id in cocoa. Do you have any po开发者_StackOverflow中文版inter for this?


First, use CGWindowListCreateDescriptionFromArray() to get the PID of the owning process (kCGWindowOwnerPID). If this is 10.6, you can then use +[NSRunningApplication runningApplicationWithProcessIdentifier:] to get the application object and then use -icon.

Before 10.6, you need to use GetProcessForPID() to switch to a PSN, use GetProcessBundleLocation() to get the location of the bundle, switch the FSRef into a path string, and then use -[NSWorkspace iconForFile:] to get the icon.


Rob Napier's answer is correct.

In the latest api and in swift language, it should be like this:

let runningApp = NSRunningApplication(processIdentifier: pid_t(the_process_id))
let icon = runningApp?.icon
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜