使用WinAPI获取与正在运行的应用程序关联的图标

时间:2009-09-25 17:12:54

标签: winapi

如果我知道Hwnd,我怎样才能获得正在运行的应用程序的图标?

2 个答案:

答案 0 :(得分:2)

如果您有窗口的句柄,则可以使用GetClassLong

HICON icon = (HICON)GetClassLong(window, GCL_HICON);

答案 1 :(得分:0)

我有你可以使用WINAPI GetWindowThreadProcessId获取进程ID的hwnd。 有了它,您可以创建一个C#Process对象。接下来,您可以遍历进程'ProcessModule Collection以获取可执行文件的文件名。最后,您可以使用WINAPI函数ExtractIconEx从路径

获取图标

Pinvoke有关于两个WINAPI方法的信息

http://www.pinvoke.net/default.aspx/user32/GetWindowThreadProcessId.html

http://www.pinvoke.net/default.aspx/shell32/ExtractIconEx.html

相关问题